mypy doesn't detect use before declaration when on the same line and there is a function call
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 doesn't detect use before declaration when:
- the use is on the same line as the declaration.
- there is a function call around the used-before-declaration variable
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=0d661a8817115f77bed9a655fe21fba1
Expected Behavior
A "Name "i" is not defined" error is raised - since the code fails at runtime.
Actual Behavior
No errors reported
Note:
- replacing
int(...)with a different function (e.g., a user-defined one) also produces the bug as long as the argument of the function isint. - Removing the function call (
i: int = i) makes mypy properly produce the error "Name "i" is not defined".
Your Environment
- Mypy version used: 1.4.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.10.6
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 la riproduzione collegata in mypy-play e confronta l’assegnazione annotata sulla stessa riga con e senza la chiamata alla funzione. Traccia il modo in cui mypy analizza l’annotazione e l’inizializzatore, quindi aggiungi un test di regressione che copra il caso segnalato e verifica che emetta un errore "Name "i" is not defined".
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
- 35/100