Mypy reports a function is "missing return statement" when unused imports are removed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den Unterschied zwischen mypy mesonbuild/compilers/detect.py und ./run_mypy.py mit Python 3.10, mypy 0.971 und .mypy.ini zu reproduzieren. Vergleiche die referenzierten Revisionen und untersuche mesonbuild/compilers/detect.py zusammen mit run_mypy.py; als abgeschlossen gilt die Aufgabe, wenn erklärt ist, warum das Entfernen ungenutzter Imports die aggregierte Prüfung verändert, und die inkonsistente Diagnose korrigiert wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100