mypy assumes `importlib.metadata` is implicitly imported via `importlib`?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
mypy seems to assume that import importlib brings in the relevant submodules (though I can't see anything in typeshed that would indicate this?) even though it does not
importlib.metadata is not implicitly brought in by importlib:
$ python3 -c 'import importlib; importlib.metadata'
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'metadata'
To Reproduce
import importlib
reveal_type(importlib.metadata) # expected error but none?
import urllib
reveal_type(urllib.parse) # similar situation but properly errors!
Expected Behavior
I expect two errors, but I only get one
Actual Behavior
$ mypy t.py
t.py:3: note: Revealed type is "types.ModuleType"
t.py:7: error: Module has no attribute "parse" [attr-defined]
t.py:7: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.13.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.13.0
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 mit der minimalen Reproduktion in t.py und führe sie mit mypy 1.13.0 unter Python 3.13 aus. Vergleiche, wie mypy importlib.metadata im Vergleich zu urllib.parse behandelt, und verfolge anschließend die für die unterschiedlichen Diagnosen verantwortliche Importverarbeitung. Erledigt ist die Aufgabe, wenn mypy den fehlenden Zugriff auf importlib.metadata meldet und den bestehenden urllib.parse-Fehler beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100