python / python/mypy

Bug - Type aliasing typing.Tuple is treated as if the empty Tuple is being aliased

Aperta
#8,715 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-type-alias
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

This is a bug report.

Type aliasing typing.Tuple is treated as if the empty tuple (typing.Tuple[()]) is being aliased.

Here is some sample code that converts Polar coordinates into Cartesian:

import math
import typing

Tuple = typing.Tuple


def cartesian(r: int, θ: int) -> Tuple[float, float]:
    rad = math.radians(θ)
    return r*math.cos(rad), r*math.sin(rad)


r = 12
θ = 195

x,y = cartesian(r, θ)
print(f"({r}, {θ}°) = ({x:.2f}, {y:.2f})")

$ python3 example.py 
(12, 195°) = (-11.59, -3.11)
$ mypy example.py 
example.py:7: error: Bad number of arguments for type alias, expected: 0, given: 2
Found 1 error in 1 file (checked 1 source file)

What is the actual behavior/output?

example.py:7: error: Bad number of arguments for type alias, expected: 0, given: 2
Found 1 error in 1 file (checked 1 source file)

What is the behavior/output you expect?

Success: no issues found in 1 source file

Such as when from typing import Tuple is used instead.

What are the versions of mypy and Python you are using?

I'm using mypy version 0.77 installed using pip and Python 3.7.7 instead via homebrew on macOS Catalina 10.15.4.

Do you see the same issue after installing mypy from Git master?

Yes.

What are the mypy flags you are using? (For example --strict-optional)

None.

Additional details

It might be related to #8273. I know Tuple and Callable are both mentioned in PEP 484 as being different.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione in example.py ed esegui mypy senza flags aggiuntivi, confrontando l’annotazione aliased typing.Tuple con l’importazione diretta descritta nel report. Il lavoro è completato quando la forma aliased supera con successo il controllo dei tipi con l’output previsto “Success: no issues found”.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.