Next steps for type introspection and stub generation
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
This is an incomplete list of next steps to build proper stubs from PyO3 codebases:
- introspect all class methods (including adding a test for all magic methods) (partial: #5273)
- introspect classes associated constants (
const) #5272 - introspect modules associated constants (
const) #5096 - introspect simple enums built by
#[pyclass] - introspect complex enums built by
#[pyclass] - introspect exceptions built by
create_exception! - introspect class inheritance (
#[pyclass(extends=)]) #5331 -
@typing.finaldecorator on class that cannot be subclasses (without#[pyclass(subclass)]) #5552 - introspect auto-generated magic methods (
#[pyclass(eq, eq_int, ord, hash, str)]) #5338 - introspect fields getter and setter (
#[pyo3(get, set)],#[pyclass(get_all, set_all)]) #5370 - implement return type annotation #5208
- fill
PYTHON_TYPEconstant on all implementations of the relevant traits (FromPyObjectandIntoPyObject) #5634 #5637 #5639 #5640 - fill
INPUT_TYPEin#[derive(FromPyObject)]#5339 - fill
OUTPUT_TYPEin#[derive(IntoPyObject)]#5365 - figure out how to emit
#[classattr]in the stubs #5839 - support cross-modules types (class defined in module A and used in module B as an input/output type)
- add doc strings to the generated stubs #5782
- proper test coverage
- proper formatting of stubs (not a blocker)
- integration into
maturin - proper type stubs for containers (
list[T]instead oflist). #5639 - allow to set custom type annotations (both inputs and output) #5241
- allow to set custom stubs for eg. protocols
- add
_typeshed.Incompleteto relevant places (modules with a#[pymodule_init]function...) (doc) #5207 - choose between
_typeshed.Incompleteandtyping.Anyin type annotations - make sure to properly gate introspection element with
cfgmacros - provide a way to set
@overloads - Support WASM files in
pyo3-introspection - Allow custom type annotations without strings (example:
#[pyo3(signature = (arg: list[int]) -> list[int])]) - Add version information to the generated JSON blobs
- Figure out if the function used to tag incomplete modules should be generated by pyo3-macros instead
- Make sure we don't try to import
Nonefrombuiltins, it does not work
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
This issue is a roadmap for pyo3-introspection, stub generation, maturin integration, and pyo3-macros rather than a single scoped change. Choose one unchecked item, read the linked stubs reference and the relevant existing introspection behavior, then define completion as that item being implemented with proper test coverage and correctly formatted generated stubs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100