Skip to content

fix(packaging): ship PEP 561 py.typed marker so downstream type checkers see the annotations#34

Open
rohithreddy66666 wants to merge 1 commit into
sochdb:mainfrom
rohithreddy66666:chore/pep561-py-typed
Open

fix(packaging): ship PEP 561 py.typed marker so downstream type checkers see the annotations#34
rohithreddy66666 wants to merge 1 commit into
sochdb:mainfrom
rohithreddy66666:chore/pep561-py-typed

Conversation

@rohithreddy66666

Copy link
Copy Markdown

Summary

Ships the PEP 561 py.typed marker so downstream mypy / Pyright / VS Code Pylance see the SDK's already-written type annotations. 15-line diff, packaging-only, no .py source 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:

error: Skipping analyzing "sochdb": module is installed, but missing library stubs or py.typed marker  [import-untyped]

…and treating the entire sochdb package as untyped Any. Every type hint the SDK ships was invisible to consumers.

Fix

  1. Add an empty src/sochdb/py.typed (0 bytes, per PEP 561 §Packaging Type Information — an empty marker is sufficient).
  2. Register "py.typed" in the sochdb list under [tool.setuptools.package-data] in pyproject.toml so it lands in the built wheel.
  3. Document under a new ## [Unreleased]### Fixed in CHANGELOG.md.

No .py source 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 install receives it:

$ pip wheel . --no-deps -w /tmp/wc
$ python -m zipfile -l /tmp/wc/sochdb-0.8.3-py3-none-any.whl | grep py.typed
sochdb/py.typed                                              0

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:

# consumer.py
from sochdb import Database
wrong: str = Database("/tmp/db")

BEFORE the fix (marker deleted from the installed sochdb):

consumer.py:1: error: Skipping analyzing "sochdb": module is installed, but
    missing library stubs or py.typed marker  [import-untyped]
Found 1 error in 1 file (checked 1 source file)

Database collapses to Any. Two real bugs on line 2 are completely invisible.

AFTER the fix (marker present):

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]
Found 2 errors in 1 file (checked 1 source file)

→ mypy resolves the real Database class from sochdb/database.py, catches the missing _handle argument, and catches the str = Database mismatch. This is the type-safety downstream consumers should have had all along.

3. Standard checks

  • python -m compileall -q src/sochdb — clean
  • ruff check --select E9,F63,F7 --exclude "src/sochdb/sochdb_pb2*.py" src/ tests/ — All checks passed
  • python -c "import tomllib; tomllib.load(open('pyproject.toml','rb'))" — parses; "py.typed" present in [tool.setuptools.package-data].sochdb
  • Working-tree diff was byte-verified to have 0 trailing-whitespace lines added or removed (defended against editor format-on-save collateral)

Diff

 CHANGELOG.md   | 13 +++++++++++++
 pyproject.toml |  2 ++
 2 files changed, 15 insertions(+)

Plus a new 0-byte src/sochdb/py.typed.

Rebase note

If a parallel PR also touches ## [Unreleased] in CHANGELOG.md, this one will need a trivial rebase to consolidate under one section — happy to do that on request.

…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
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.

1 participant