enumerate(Union[Sequence, Sequence])
Offen
Dieses Issue hat noch niemand übernommen.
feature
needs discussion
topic-join-v-union
topic-type-variables
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
- Are you reporting a bug, or opening a feature request?
Bug - Please insert below the code you are checking with mypy.
from typing import Sequence, Union
def baz(idx: int, arg: Union[int, str]) -> None:
pass
def foo(the_list: Union[Sequence[int], Sequence[str]]) -> None:
for idx, val in enumerate(the_list):
reveal_type(idx)
reveal_type(val)
baz(idx, val)
- What is the actual behavior/output?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'builtins.object*'
foo.py:10: error: Argument 2 to "baz" has incompatible type "object"; expected "Union[int, str]"
- What is the behavior/output you expect?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'Union[int, str]'
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
0.761, 0.770 and master all have the same result. - What are the mypy flags you are using? (For example --strict-optional)
--strict
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
Reproduziere das Beispiel in foo.py mit mypy und den gemeldeten --strict-Flags und untersuche dann den Pfad der Typinferenz für enumerate über eine Union von Sequenzen. Erledigt ist es, wenn reveal_type(val) Union[int, str] meldet und der Aufruf von baz akzeptiert wird, ohne andere Prüfungen abzuschwächen.
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
- 35/100