stubgen doesn't find c modules in namespace of python package
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beschreibung
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
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 in mypy/moduleinspect.py bei der im Issue beschriebenen pkgutil.walk_packages()-Logik und verfolge anschließend, wie stubgen reguläre Paketinhalte erkennt. Reproduziere das Problem mit dem bereitgestellten GDB-Wrapper und überprüfe die generierten Stubs für gdb.Architecture und andere C-Module. Die Aufgabe ist abgeschlossen, wenn in den generierten .pyi-Dateien C-Erweiterungsmodule erscheinen, die im Paket-Namespace verfügbar gemacht werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100