Skip to content

fix(bindings): ship the PEP 561 marker so type checkers read the Python package - #586

Merged
bahdotsh merged 1 commit into
Offline-Protocol:mainfrom
marioolf:fix/python-py-typed
Oct 20, 2026
Merged

bahdotsh merged 1 commit into
Offline-Protocol:mainfrom
marioolf:fix/python-py-typed

Conversation

@marioolf

@marioolf marioolf commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Python package is annotated throughout, but it shipped no PEP 561 py.typed marker. So mypy treats offline_protocol_sdk as untyped: every import fails with import-untyped, and every value the SDK returns is Any in the application.

This PR:

  • adds the empty bindings/python/offline_protocol_sdk/py.typed;
  • lists it in [tool.setuptools.package-data], which otherwise carries only the native libraries, so setuptools would leave the marker out of the wheel;
  • adds the Typing :: Typed classifier;
  • adds the marker to the list of files scripts/build-wheel.sh requires in the wheel, so the release build fails if it ever goes missing.

Before and after

A consumer script against the installed wheel:

from offline_protocol_sdk.relay_answer_prefixes import is_relay_answer

reveal_type(is_relay_answer)
is_relay_answer(42)  # wrong argument type: a str is expected

Without the marker (the current release):

app.py:1: error: Skipping analyzing "offline_protocol_sdk.relay_answer_prefixes": module is installed, but missing library stubs or py.typed marker  [import-untyped]
app.py:3: note: Revealed type is "Any"

With the marker:

app.py:3: note: Revealed type is "def (prefix: str) -> bool"
app.py:4: error: Argument 1 to "is_relay_answer" has incompatible type "int"; expected "str"  [arg-type]

Related issues

None.

Type of change

  • fix: bug fix

Checklist

  • Commits follow Conventional Commits
  • CHANGELOG.md updated (Unreleased, Fixed)
  • No Rust, UDL or binding-generation change, so the cargo gates and binding regeneration don't apply.

Breaking changes

None. An application already running mypy on code that uses the SDK will start getting real type errors where it used to get Any. That is the intended effect, and mypy does not report errors inside an installed package's own source.

Notes for reviewers

How I verified it:

  • Built the wheel with uv build --wheel and checked it contains offline_protocol_sdk/py.typed and carries Classifier: Typing :: Typed in its metadata.
  • Ran the same required-files check build-wheel.sh uses against that wheel and against a copy with the marker removed: the first passes, the second reports ['offline_protocol_sdk/py.typed'] missing. bash -n passes on the script.
  • The mypy before and after above, run against that wheel installed in a clean venv.
  • I did not run build-wheel.sh end to end, since it needs the native library built for each platform. CI's wheel job runs it.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@marioolf

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 19, 2026
…on package

The package is annotated throughout but shipped no `py.typed`, so mypy
skipped it as untyped ("missing library stubs or py.typed marker") and
every value it returned was `Any` in the application.

Add the empty marker, list it in the setuptools package data (which
otherwise carries only the native libraries), add the `Typing :: Typed`
classifier, and make build-wheel.sh refuse a wheel without it.
@marioolf
marioolf force-pushed the fix/python-py-typed branch from f28c4da to 09b5f4c Compare October 19, 2026 20:30
@marioolf marioolf changed the title fix(bindings): ship the PEP 561 marker so type checkers read the Pyth… fix(bindings): ship the PEP 561 marker so type checkers read the Python package Oct 19, 2026

@bahdotsh bahdotsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you so much for raising the PR!

LGTM!

@bahdotsh
bahdotsh merged commit c7f468a into Offline-Protocol:main Oct 20, 2026
27 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants