Mypy not reporting "undefined" variable.
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
When using a "undefined" variable, which will immediately crash the code when running it, mypy does not report anything about it. Is it normal ?
I feel like mypy should report it but maybe I am wrong because this isn't a typing error. On the other hand, this error is only possible because typing annotations exist . What do you think ?
To Reproduce
Dump this in a file main.py:
number: int
print(number)
Gist URL: https://gist.github.com/mypy-play/31d3775229a6fe01af6bbb09b9230a18
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=31d3775229a6fe01af6bbb09b9230a18
Expected Behavior
An error message, maybe something like this.
main.py:2: error: Using an undefined variable, a value must be set before first. [var-undefined]
Actual Behavior
$ mypy --strict main.py
Success: no issues found in 1 source file
python main.py
Traceback (most recent call last):
File "/home/user/main.py", line 2, in <module>
print(number)
^^^^^^
NameError: name 'number' is not defined
Your Environment
- Mypy version used: 1.3.0
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): nothing - Python version used: 3.11.3
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 il comportamento con l’esempio main.py e mypy --strict main.py. Esamina come il checker gestisce una variabile che ha solo un’annotazione prima di decidere se questo caso debba ricevere una diagnosi come [var-undefined]. Il lavoro è completato quando il comportamento è coperto da un test e da una diagnosi appropriati, oppure quando il comportamento previsto è documentato come non supportato.
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