Uncaught Error in Assignment of type Iterator[int] to type Iterator[str]
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
Mypy allows the assignment
it: Iterator[str] = iter(d) where d is dict[int, str].
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=05c55a654acd175b763be1c73567a107
from typing import Iterator
d: dict[int, str] = {1: 'A'}
it: Iterator[str] = iter(d) # mypy does not complain, although iter(d) has type Iterator[int]!
s = next(it) + 'foo' # TypeError: unsupported operand type(s) for +: 'int' and 'str'
Expected Behavior
Mypy raises an error such as
error: Argument 1 to "iter" has incompatible type "dict[int, str]"; expected "SupportsIter[Iterator[str]]"
Actual Behavior
Success: no issues found in 1 source file
Your Environment
mypy Playground
- Mypy version used: mypy latest 1.17.1
- Mypy command-line flags: --strict
- Python version used: 3.12
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 con il riproduttore collegato di mypy-play.net e l’espressione iter(d), usando mypy 1.17.1 con --strict su Python 3.12. Traccia il modo in cui il type checker inferisce il tipo dell’iteratore per un dict[int, str] e aggiungi un test di regressione che mostri che l’assegnazione a Iterator[str] viene rifiutata.
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
- Specificata chiaramente
- Idoneità per principianti
- 38/100