fix(packaging): ship PEP 561 py.typed marker so downstream type checkers see the annotations#34
Open
rohithreddy66666 wants to merge 1 commit into
Open
Conversation
…ers see the annotations
The SDK is fully type-annotated, but the PEP 561 `py.typed` marker was
neither present under `src/sochdb/` nor listed in
`[tool.setuptools.package-data]`. As a result, downstream mypy / Pyright
silently skipped analyzing `sochdb`:
Skipping analyzing "sochdb": module is installed, but missing
library stubs or py.typed marker [import-untyped]
Every shipped type hint was invisible to consumers.
Fix:
- Add an empty `src/sochdb/py.typed` file (per PEP 561 §Packaging Type
Information — an empty marker is sufficient and signals the package is
fully typed).
- Add `"py.typed"` to the `sochdb` list under
`[tool.setuptools.package-data]` in `pyproject.toml` so it's included
in the built wheel alongside the bundled native libraries.
- CHANGELOG entry under a new `## [Unreleased]` -> `### Fixed`.
No `.py` source is touched; no public API change; no ABI or FFI change;
`__version__` / `__core_version__` unchanged.
Reproduction (verified locally with mypy 2.3.0 on Python 3.13):
# tiny downstream consumer
$ cat consumer.py
from sochdb import Database
wrong: str = Database("/tmp/db")
# BEFORE the fix (marker absent from installed sochdb):
$ mypy consumer.py
consumer.py:1: error: Skipping analyzing "sochdb": module is
installed, but missing library stubs or py.typed marker
[import-untyped]
# -> Database is treated as Any, two real bugs missed.
# AFTER the fix (marker present):
$ mypy consumer.py
consumer.py:2: error: Missing positional argument "_handle" in call
to "Database" [call-arg]
consumer.py:2: error: Incompatible types in assignment (expression
has type "Database", variable has type "str") [assignment]
# -> real class signatures resolved, real bugs caught.
Wheel-content verification:
$ pip wheel . --no-deps -w /tmp/wc && \
python -m zipfile -l /tmp/wc/sochdb-*.whl | grep py.typed
sochdb/py.typed 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships the PEP 561
py.typedmarker so downstream mypy / Pyright / VS Code Pylance see the SDK's already-written type annotations. 15-line diff, packaging-only, no.pysource touched.Problem
The SDK is fully type-annotated, but the marker was neither present under
src/sochdb/nor listed in[tool.setuptools.package-data]. Every downstream user's type checker was silently emitting:…and treating the entire
sochdbpackage as untypedAny. Every type hint the SDK ships was invisible to consumers.Fix
src/sochdb/py.typed(0 bytes, per PEP 561 §Packaging Type Information — an empty marker is sufficient)."py.typed"in thesochdblist under[tool.setuptools.package-data]inpyproject.tomlso it lands in the built wheel.## [Unreleased]→### FixedinCHANGELOG.md.No
.pysource touched. No public API change. No FFI / ABI change.__version__/__core_version__unchanged.Testing — verified locally before pushing
1. Wheel-content check
Confirmed the marker is packaged so downstream
pip installreceives it:2. Real mypy before/after
mypy 2.3.0 on Python 3.13, installed into an isolated venv against the built wheel. Same consumer script both times:
BEFORE the fix (marker deleted from the installed sochdb):
→
Databasecollapses toAny. Two real bugs on line 2 are completely invisible.AFTER the fix (marker present):
→ mypy resolves the real
Databaseclass fromsochdb/database.py, catches the missing_handleargument, and catches thestr = Databasemismatch. This is the type-safety downstream consumers should have had all along.3. Standard checks
python -m compileall -q src/sochdb— cleanruff check --select E9,F63,F7 --exclude "src/sochdb/sochdb_pb2*.py" src/ tests/— All checks passedpython -c "import tomllib; tomllib.load(open('pyproject.toml','rb'))"— parses;"py.typed"present in[tool.setuptools.package-data].sochdbDiff
Plus a new 0-byte
src/sochdb/py.typed.Rebase note
If a parallel PR also touches
## [Unreleased]inCHANGELOG.md, this one will need a trivial rebase to consolidate under one section — happy to do that on request.