PyO3 / PyO3/pyo3

`experimental-inspect`: Add `stubtest` test in CI to ensure generated stubfiles match binary interfaces

Open
#6,240 0 comments 1 reaction 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

There is no test asserting stubtest is happy, only a commented-out TODO at pytests/noxfile.py:49.

There are some issues though that would have to be fixed before simply enabling a stubtest test in CI:

  1. pyo3_pytests isn't importable in the stub layout. type_checker does copytree("stubs", "pyo3_pytests"), making it a mixed-project source dir of only .pyi files, so maturin generates no __init__.py, #[pymodule_init] never runs and no submodule is importable. Fine for the static-only mypy session, fatal for stubtest.

  2. 43 unrelated gaps remain once it is importable:

    Count Gap
    16 __all__ is set at runtime by #[pymodule] but never emitted into the stubs
    15 submodules aren't declared in __init__.pyi; stubtest doesn't accept the incomplete-module __getattr__ as covering them
    6 @disjoint_base isn't emitted for classes that can't be subclassed
    3 annotations, consts, exception aren't registered in sys.modules by pytests/src/lib.rs (fixture gap)
    1 Number.__pow__'s modulo has a runtime default the stub doesn't express
    1 the inner pyo3_pytests.pyo3_pytests module has no .pyi

Two smaller adjacent defects, also left alone: slot parameters with a runtime default are emitted without one (__pow__'s modulo, __get__'s owner), and reflected operators (__radd__, __rpow__, …) exist at runtime but never reach the stubs.

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

Start at the commented-out TODO in pytests/noxfile.py:49 and inspect the type_checker session's stubs-to-pyo3_pytests layout. Then read pytests/src/lib.rs and compare the generated stubs with the listed stubtest gaps, including submodules, all, disjoint bases, defaults, and reflected operators. Done means CI runs stubtest successfully without the documented gaps.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
backend, ci-cd, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.