FOO and next(iter(FOO))
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
Python code
FOO = frozenset("abc")
BAR = FOO and next(iter(FOO))
Mypy reports and error
wtf.py:2: error: Argument 1 to "iter" has incompatible type "FrozenSet[str]"; expected "Iterable[FrozenSet[str]]"
Expected Behavior
Ideally, mypy should infer that type of BAR is "falsey or string".
If not that, then "empty set or string".
if not that, then "set or string".
Actual Behavior
mypy seems to be tripped by X op func(X), gets confused 😖
mypy complains about the argument to iter 🤷🏿
Note that expression like BAR = next(iter(FOO)) is understood correctly.
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.5
- Operating system and version: macos, universal2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l’esempio Python minimo con mypy 0.910 e verifica come il type checker gestisce l’espressione booleana and intorno a iter(FOO). L’attività è completata quando l’esempio non segnala più un errore di argomento incompatibile e il tipo inferito di BAR corrisponde a una delle alternative previste.
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
- 42/100