Skip to content

Conversation

@simu
Copy link
Member

@simu simu commented Dec 17, 2025

We switch to managing the Python package contents ourselves, so we can include the type stubs in a way which makes mypy's stubtest happy.

Notably stubtest will complain about missing type stubs if we don't provide both __init__.pyi and reclass_rs.pyi. Note that we provide __init__.pyi as a symlink to reclass_rs.pyi since the __init__.py only re-exports the API of the native reclass_rs submodule.

The PR also switches the Python module definition in rust from fn reclass_rs() to mod reclass_rs (in anticipation of PyO3's WIP introspection & type stub generation tooling) and we add a CI step which runs mypy and mypy's stubtest to provide basic validation for our type stubs.

Unfortunately, from some limited testing, stubtest doesn't necessarily catch incorrect type stubs, since some of the PyO3 generated functions apparently have very limited metadata (especially for return types).

Checklist

  • The PR has a meaningful title. The title will be used to auto generate the changelog
  • PR contains a single logical change (to build a better changelog).
  • Update the documentation.
  • Update tests.
  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency, internal
    as they show up in the changelog

@simu simu added the enhancement New feature or request label Dec 17, 2025
@github-actions

This comment was marked as outdated.

@simu simu force-pushed the feat/python-type-stubs branch from 70fe39c to b7274fe Compare December 17, 2025 10:07
@simu simu changed the title Feat/python type stubs Setup Python type stubs for reclass_rs Dec 17, 2025
@github-actions

This comment was marked as outdated.

@simu simu marked this pull request as ready for review December 17, 2025 10:16
@simu simu requested a review from a team December 17, 2025 10:17
simu added 2 commits December 17, 2025 14:53
We switch to managing the Python package contents ourselves, so we can
include the type stubs in a way which makes mypy's `stubtest` happy.

Notably `stubtest` will complain about missing type stubs if we don't
provide both `__init__.pyi` and `reclass_rs.pyi`.
We extend the x86_64 Python workflow to run `stubtest` and `mypy` to get
basic validation for the type stubs. This should be sufficient to catch
PRs that introduce new Python API surface without adding type stubs.

Unfortunately, from some limited testing, `stubtest` doesn't necessarily
catch incorrect type stubs, since some of the PyO3 generated functions
apparently have very limited metadata (especially for return types).
@simu simu force-pushed the feat/python-type-stubs branch from b7274fe to 306887f Compare December 17, 2025 13:53
@github-actions
Copy link

Benchmark for 2520952

Click to view benchmark
Test Base PR %
Reclass::inventory() multi-threaded 2.3±0.19ms 2.3±0.13ms 0.00%
Reclass::inventory() single-threaded 4.6±0.03ms 4.5±0.03ms -2.17%

@simu simu merged commit b94e6e0 into main Dec 17, 2025
22 checks passed
@simu simu deleted the feat/python-type-stubs branch December 17, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants