Mypy reports a function is "missing return statement" when unused imports are removed
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
I know this sounds ridiculous, but I'm not sure how else to explain it. In the middle of a large refactor of code, which can be found here in its original, mypy-passing state:
I have a function which looks like this:
def _handle_exceptions(data: StuffICareAbout) -> typing.NoReturn:
raise mesonlib.EnvironmentException(f'{data} happened and this is bad')
def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker:
data = do_stuff()
if foo_condition:
return StaticLinkerA()
elif bar_condition:
return StaticLinkerB()
_handle_exceptions(data)
mypy says this is fine. detect_static_linker() doesn't always return, but if it doesn't return, it runs a function that is guaranteed to never return, always raise.
This somehow stops working during the course of this series of changes, which doesn't affect the high-level overview of that function: https://github.com/eli-schwartz/meson/compare/83d18d137dc50437a8263983e8883198c7bc41ed...681609624b687d660b234a9393d446a8f2f6663b
After way too much troubleshooting, and separating out parts of the commit to see what caused it, I produced the above series of commits, and...
... this commit is fingered by git bisect: https://github.com/eli-schwartz/meson/compare/fe42a1cadade94cb39e2761500a1f5849ad7d2e8...b1676e57f60c6a1fb7533096402ae5c8ff713a35
All it does is finally drop the unused imports rendered redundant by the previous commit. I don't understand how this could be possible.
Furthermore, if I run mypy mesonbuild/compilers/detect.py, mypy passes. If I run ./run_mypy.py, a script that contains a list of files to check, and runs mypy "list" "of" "files", it triggers the issue.
Discussion in the meson review can be seen here, in case that's interesting (two people failed to reproduce it locally at first): https://github.com/mesonbuild/meson/pull/10810#discussion_r970164045
Your Environment
- Mypy version used: 0.971
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): https://github.com/mesonbuild/meson/blob/master/.mypy.ini - Python version used: 3.10
- Operating system and version: Arch Linux
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 la differenza tra mypy mesonbuild/compilers/detect.py e ./run_mypy.py, usando Python 3.10, mypy 0.971 e .mypy.ini. Confronta le revisioni indicate e analizza mesonbuild/compilers/detect.py insieme a run_mypy.py; il lavoro è concluso quando viene spiegato perché la rimozione degli import inutilizzati modifica il controllo aggregato e viene corretta la diagnostica incoerente.
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
- 45/100