Skip to content

Add PEP 561 type stubs for chialisp - #491

Merged
Quexington merged 5 commits into
mainfrom
add-type-stubs
Jun 25, 2026
Merged

Quexington merged 5 commits into
mainfrom
add-type-stubs

Conversation

@emlowe

@emlowe emlowe commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adopts the same pattern as chiavdf/chiabip158: a private _chialisp Rust extension re-exported from a pure-Python chialisp package with py.typed and __init__.pyi.
  • Replaces the legacy python/clvm_tools_rs/ shim with a proper python/chialisp/ mixed layout (module-name = "chialisp._chialisp").
  • Adds a typing CI job that builds the package with maturin and runs stubtest --concise chialisp.

This lets chia-blockchain remove [mypy-chialisp.*] ignore_missing_imports = True once a release is published.

Approach

Piece Role
chialisp/_chialisp.abi3.so Private PyO3 extension (renamed from chialisp)
chialisp/__init__.py Explicit public re-exports + sys.modules registration for binutils
chialisp/__init__.pyi Typed public API (compile_clvm, start_clvm_program, etc.)
chialisp/binutils.pyi Stubs for the binutils submodule
chialisp/py.typed PEP 561 marker

Public imports are unchanged: from chialisp import compile_clvm.

Test plan

  • maturin build --release produces wheel with _chialisp.abi3.so, stubs, and py.typed
  • stubtest --concise chialisp passes locally
  • CI typing job passes
  • Existing wheel/integration tests still pass

Made with Cursor


Note

Low Risk
Packaging and typing surface changes only; public from chialisp import … API is preserved via re-exports, with risk mainly around wheel layout and the removed clvm_tools_rs shim path.

Overview
Adds PEP 561 typing for the chialisp package using a mixed Rust/Python layout: maturin now builds a private extension chialisp._chialisp (PyO3 module renamed in api.rs), while python/chialisp/ holds the public __init__.py re-exports, py.typed, and __init__.pyi / binutils.pyi stubs. pyproject.toml sets python-source and module-name accordingly; .gitignore ignores local *.abi3.so builds.

Removes the old python/clvm_tools_rs/ star-import shim and its cmds.py helper (compatibility for tests still goes through ./tmp in CI, unchanged in this diff).

Adds a typing CI job that builds the wheel with maturin and runs stubtest --concise chialisp so the published API matches the stubs.

Reviewed by Cursor Bugbot for commit ee6b17b. Bugbot is set up for automated code reviews on this repo. Configure here.

Move the public API behind a private _chialisp extension module with
__init__.pyi, py.typed, and stubtest CI so downstream mypy can drop
ignore_missing_imports for chialisp.

Co-authored-by: Cursor <cursoragent@cursor.com>
@emlowe
emlowe requested a review from prozacchiwawa June 3, 2026 20:49
emlowe and others added 2 commits June 3, 2026 14:03
The typing job cannot use maturin develop without a venv on GitHub
Actions. Build the wheel and pip install it instead.

Also apply clippy's manual_option_zip suggestion in serialize.rs so the
pinned toolchain job passes with -D warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop the nested chialisp checkout and compiled extension module from
the branch, and ignore *.abi3.so going forward.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d186618. Configure here.

Comment thread src/classic/clvm/serialize.rs Outdated
emlowe and others added 2 commits June 3, 2026 14:08
Keep the typing PR scoped to PEP 561 stubs and CI; the clippy lint
in serialize.rs is pre-existing on main and should be fixed separately.

Co-authored-by: Cursor <cursoragent@cursor.com>
@prozacchiwawa

Copy link
Copy Markdown
Contributor

Neat.

@emlowe
emlowe marked this pull request as ready for review June 4, 2026 16:40
@Quexington
Quexington merged commit da77e20 into main Jun 25, 2026
38 checks passed
@Quexington
Quexington deleted the add-type-stubs branch June 25, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants