Relative imports in stub modules checking live code
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
Hi all! I'm trying to get to the bottom of this issue with stub imports, and I can't even find information to tell me if this is actually expected behaviour. Please see repro.
To Reproduce
A quick setup running this series of shell commands follows:
>>> $ mkdir module
>>> $ mkdir module-stubs
>>> $ touch module/__init__.py
>>> $ touch module-stubs/submodule.pyi
>>> $ echo "from . import submodule" > module-stubs/__init__.pyi
>>> $ echo "import module" > run.py
>>> $ mypy run.py
module-stubs/__init__.pyi:1: error: Module 'module' has no attribute 'submodule'
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
I would have expected that an import within the stub module still would understand that the stub module exists, and use the stub submodule to verify the import.
The real module can be doing any number of dynamic things during the import to ensure "submodule" is available.
OR this is expected behaviour and I need to adjust my expectations.
Actual Behavior
The result appears to be that mypy goes looking in the actual python package for the module and not within the stub.
module-stubs/__init__.pyi:1: error: Module 'module' has no attribute 'submodule'
Actually creating the submodule in the python package removes this error.
Your Environment
Mypy versions tested on 0.931 and 0.812 with same results.
OS version: linux mint 20.3
Thanks a lot everyone.
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
Riproduci il report usando i comandi shell nell’issue, in particolare module-stubs/init.pyi, module-stubs/submodule.pyi e run.py. Inizia tracciando il modo in cui mypy risolve l’import relativo nel pacchetto di stub; il lavoro è completo quando il comportamento è documentato oppure l’import viene risolto in modo coerente con la semantica prevista del modulo stub.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100