Mypy does not recognize pkg_resources-style namespace packages
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 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
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 mypy . sui directory root ed extensions riprodotti, concentrandoti sui due file namespace __init__.py che chiamano pkg_resources.declare_namespace. Traccia la mappatura dei percorsi dei moduli di mypy per questi file e aggiungi la copertura per il layout segnalato; il lavoro è completato quando il comando non segnala più un modulo root duplicato.
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