PyO3 / PyO3/pyo3

Next steps for type introspection and stub generation

Open
#5,137 30 comments 59 reactions 0 assignees View on GitHub

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.final decorator 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_TYPE constant on all implementations of the relevant traits (FromPyObject and IntoPyObject) #5634 #5637 #5639 #5640
  • fill INPUT_TYPE in #[derive(FromPyObject)] #5339
  • fill OUTPUT_TYPE in #[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 of list). #5639
  • allow to set custom type annotations (both inputs and output) #5241
  • allow to set custom stubs for eg. protocols
  • add _typeshed.Incomplete to relevant places (modules with a #[pymodule_init] function...) (doc) #5207
  • choose between _typeshed.Incomplete and typing.Any in type annotations
  • make sure to properly gate introspection element with cfg macros
  • 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 None from builtins, it does not work

Reference on stubs file

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.