Consider using stubgen-pyx for automatic Cython stub generation #13920
jon-edward
started this conversation in
New Features & Project Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
I'd like to propose integrating
stubgen-pyxto automatically generate Python stub files (.pyi) from spaCy's Cython source code. I am the creator and maintainer of this utility.Problem Statement
spaCy's Cython modules currently have limited IDE support. IDE tooling cannot access type hints and docstrings embedded in Cython source code, putting the user at a disadvantage if they're accessing a Cython module that doesn't have a handwritten
.pyifile or if the.pyifile is out-of-date (or incomplete).In addition to this, a spaCy developer must keep the
.pyifile up-to-date when making changes to the Cython source, which is a time-consuming and error-prone process.These difficulties might lead to the following user frustrations:
Proposed Solution
Integrate
stubgen-pyx, a specialized stub generation tool for Cython, which offers:Key Benefits
.pyxand.pxdfiles directly using the Cython compiler's ASTbint→bool,unicode→str) to Python equivalentsImplementation Approach
stubgen-pyxas a development/build dependency.pyifiles in the distributed package for full IDE supportProof of Concept
This is the current state of
spacy/matcher/matcher.pyi:This is the result of
stubgen-pyx:The handwritten type annotations (ie.
Callable[[str, str, int], bool]) can instead be written into the Cython file, making a single source of truth instead of maintaining two versions.Configuration Example
# Generate all stubs in one command stubgen-pyx spacy/Or via Python API:
Expected Outcomes
Additional Notes
stubgen-pyxis actively maintained and available on PyPIWould the spaCy team be interested in exploring this approach? I'd be happy to help with integration or discuss any questions about the tool.
Tool References:
Beta Was this translation helpful? Give feedback.
All reactions