isinstance(x, Tuple) fails when equivalent expressions don't
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
reproducer
from typing import Any, Dict, Tuple
x = (1,2)
isinstance(x, tuple)
isinstance(x, Tuple[Any, ...])
isinstance(x, Tuple)
observed behavior
$ pipenv run mypy test.py
test.py:6: error: Argument 2 to "isinstance" has incompatible type "_SpecialForm"; expected "Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]"
expected behavior
The python documentation states
A plain Tuple is equivalent to Tuple[Any, ...], and in turn to tuple.
If the above is true, IMO either all of the examples should raise errors, or none of them should. Only the third example is raising an error right now. I'm not quite sure what the error means in any case.
environment
master as of 2019-04-15
$ pipenv graph
mypy==0.710+dev.2c8a809693cf5be0b29d272d7f0711521bd4a55a
- mypy-extensions [required: >=0.4.0,<0.5.0, installed: 0.4.1]
- typed-ast [required: >=1.3.1,<1.4.0, installed: 1.3.1]
As always, thanks for all the work you do here!
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem bereitgestellten isinstance-Reproduzierer und vergleiche, wie mypy tuple, Tuple[Any, ...] und einfaches Tuple behandelt. Verfolge den Einstiegspunkt der Typprüfung für isinstance-Aufrufe und bestimme das beabsichtigte Verhalten anhand der verlinkten Python-Dokumentation. Erledigt ist die Aufgabe, wenn die drei äquivalenten Formen konsistente, dokumentierte Diagnosen erhalten und Tests den Reproduzierer abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100