Repository navigation
feat: ship PEP 561 type stubs for the public python API - #17
mdealencar wants to merge 1 commit into
Conversation
Add type stubs for pythoncdt in src/pythoncdt/__init__.pyi and explicitly export the public API symbols in src/pythoncdt/__init__.py. While pythoncdt provided type stubs for the internal compiled extension in _core.pyi, the top-level package relied on a wildcard import without declaring type stubs or __all__. Static type checkers and language servers could not recognize re-exported symbols when consumers imported pythoncdt directly. Explicitly re-exporting the public classes, functions, and constants from _core in __init__.pyi and declaring __all__ exposes full type information for downstream users.
|
Hi, and thanks for the PR. Could you please elaborate on how to reproduce the stated problems? Strict type checkers stubtest
|
|
Sorry about that, your assessment is correct. I checked what was done differently in condeltri and mistakenly accepted the AI suggestion that was required for full static checker functionality. This means transitioning from condeltri to pythoncdt is fully drop-in. The only missing bit is the conda package. |
|
no worries at all :) |
Ship type stubs for the public pythoncdt package
Motivation & Comparison with
masterIn
master, commitab92c53introduced_core.pyifor the internal compiled extension modulepythoncdt._core. However, the top-level public packagepythoncdtrelied on a wildcard importfrom ._core import *without an__init__.pyistub and without declaring__all__.While this runtime setup allows
pythoncdt.Triangulationto work, it has concrete shortcomings for static typing and tooling:reportPrivateImportUsageor Mypy with--no-implicit-reexport), importing frompythoncdtcauses unexported symbol errors.mypy.stubtestCI gap: Becausepythoncdtlacked an__init__.pyi,mypy.stubtest pythoncdtreportederror: pythoncdt failed to find stubsand bypassed validating the top-level package entirely, checking only the internal_coresubmodule.__all__, language servers (such aspyrefly lspor Pylance) cannot cleanly distinguish the intended public surface from internal module references.__all__, runtime consumers executingfrom pythoncdt import *inadvertently import internal module attributes like_core.Changes in this PR
src/pythoncdt/__init__.pyi): Explicitly declare__all__and import all public classes, enums, functions, and constants, providing a clean PEP 561 interface for downstream type checkers.src/pythoncdt/__init__.py): Replace the wildcard import with explicit imports and declare runtime__all__in sync with__init__.pyi, resolvingmypy.stubtestrequirements and preventing_coreleakage.tests/test_bindings.py): Addtest_all_exportsto dynamically verify that every public symbol from_coreis included in__all__and resolves onpythoncdt, preventing missed bindings without duplicating symbol lists.