Mypy does not recognize pkg_resources-style namespace packages
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 is not able to understand pkg_resources-style namespace packages. Although, this is not the recommended namespace mechanism, it is still supported in Python for legacy compatibility. Especially as the documentation does not recommend to mix this method with PEP420 namespace.
To Reproduce
A project with such structure:
./root/
__init__.py # Namespace
core/
action.py
__init__.py
./extensions/
root/
__init__.py # Namespace
extra/
__init__.py
extra_action.py
where inside __init__.py as namespace, you have:
__import__("pkg_resources").declare_namespace(__name__)
Expected Behavior
$> mypy .
Success: no issues found in 6 source files
Actual Behavior
$> mypy .
root/__init__.py: error: Duplicate module named "root" (also at "./extensions/root/__init__.py")
root/__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
root/__init__.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)
Note: If all the __init__.py as namespace are removed such that it falls back to PEP420 namespace then mypy is happy:
$> mypy .
Success: no issues found in 4 source files
Your Environment
- Mypy version used:
990 - Mypy command-line flags:
mypy . - Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.9.1
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, mypy . gegen das reproduzierte root- und extensions-Verzeichnis auszuführen, wobei du dich auf die beiden Namespace-__init__.py-Dateien konzentrierst, die pkg_resources.declare_namespace aufrufen. Verfolge mypys Modulpfadzuordnung für diese Dateien und füge Abdeckung für das gemeldete Layout hinzu; abgeschlossen ist die Aufgabe, wenn der Befehl kein doppeltes root-Modul mehr meldet.
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