warn-unreachable behaves differently on else-return than on bare return
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 --warn-unreachable will error on an unreachable return after an if block but not a semantically equivalent else: return ... after an if block. This shows up in platform checking logic, as an example of "unreachable code" which mypy understands and allows.
Based on what I found in existing warn-unreachable issues, there's no report of this same issue.
To Reproduce
Run mypy --warn-unreachable on the two following samples.
This passes:
def foo():
if sys.platform != "win32":
return 1
else:
return 0
This fails (on Linux/macOS. Use == "win32" to observe on Windows):
def foo():
if sys.platform != "win32":
return 1
return 0
I also put together a small example dir of this in a github repo, if that makes it easier:
https://github.com/sirosen/repro/tree/2a56d3b/mypy-issues
Expected Behavior
mypy should pass on both of these, as they are the same.
Your Environment
- Mypy version used: 0.910
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 eseguendo i due esempi con mypy --warn-unreachable e confronta il modo in cui il type checker gestisce il return vuoto e il ramo else. Traccia l’analisi del codice irraggiungibile e aggiungi una copertura di regressione per i controlli della piattaforma; il lavoro è completato quando entrambi gli esempi semanticamente equivalenti ricevono il risultato previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100