python / python/mypy

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

Offen
#8,715 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-type-alias
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Reproduktion in example.py und führe mypy ohne zusätzliche Flags aus. Vergleiche dabei die aliased typing.Tuple-Annotation mit dem im Bericht beschriebenen direkten Import. Die Arbeit ist abgeschlossen, wenn die aliased Form erfolgreich typgeprüft wird und die erwartete Ausgabe „Success: no issues found“ erscheint.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.