stubgen doesn't find c modules in namespace of python package
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
stubgen does not find c extension modules that are placed in the namespace of a "regular" python package.
More Details:
For "regular" python packages and modules stubgen is using pkgutil.walk_packages() here to find subpackages/submodules but is not checking the namespace so it can miss some.
To Reproduce
This is how I encountered the issue (there is probably a simpler way to reproduce but I'm using gdb here as an example)
(Write your steps here:)
- get gdb with python3 support (install or download a statically compiled version)
- prepare a little wrapper script to start
stubgen:
import sys
import mypy
mypy.util.check_python_version("stubgen")
options = mypy.stubgen.Options(
pyversion=sys.version_info[:2],
no_import=False,
doc_dir="",
search_path="",
interpreter="",
ignore_errors=False,
include_private=False,
output_dir="out",
modules=[],
packages=["gdb"],
files=[],
verbose=False,
quiet=False,
export_less=False
)
mypy.stubgen.generate_stubs(options)
- start gdb and then source the previously written script:
source /path/to/script.py
(these steps are necessary because the gdb python package is only accessible through the python interpreter inside GDB)
Expected Behavior
I was expecting the pyi files to contain all objects in the gdb namespace (including the c modules that gdb puts in the gdb namespace).
Actual Behavior
E.g. gdb.Architecture (and all the other c modules) are not included (can be quickly checked by running grep -r "Architecture" inside out dir) even though they are easily accessible from withing gdb: python help(gdb.Architecture).
Your Environment
I tried it in several environments before investigating, e.g.:
- Mypy version used: both
mypy 0.761andmaster(at commit 129dba468c235fbdc01f608736554061368bcff3) - Mypy configuration options from
mypy.ini(and other config files): I used a clean env without additional configs - Python version used: Python 3.8.10
- Operating system and version: Ubuntu 20.04.3 LTS x86_64
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 in mypy/moduleinspect.py, nella logica di pkgutil.walk_packages() descritta nell’issue, quindi segui il modo in cui stubgen rileva i contenuti dei pacchetti normali. Riproduci il problema con il wrapper GDB fornito e controlla gli stub generati per gdb.Architecture e per gli altri moduli C. Il lavoro è completo quando i moduli di estensione C esposti nello spazio dei nomi del pacchetto compaiono nei file .pyi generati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100