Skip to content

feat: add type hints and py.typed marker (#18)#19

Merged
vimt merged 1 commit into
masterfrom
feat/typing-support
Jun 1, 2026
Merged

feat: add type hints and py.typed marker (#18)#19
vimt merged 1 commit into
masterfrom
feat/typing-support

Conversation

@vimt
Copy link
Copy Markdown
Owner

@vimt vimt commented Jun 1, 2026

Background

Closes #18 — Pylance reports reportMissingTypeStubs ("Fichier stub introuvable pour « mmdb_writer »"). The root cause is that the published package ships no PEP 561 py.typed marker, so type checkers won't trust the inline type hints the library already had.

Changes

  • Package + py.typed: mmdb_writer.pymmdb_writer/__init__.py, plus a new mmdb_writer/py.typed. Import paths are unchanged (from mmdb_writer import MMDBWriter, ...).
  • Complete type annotations across public and internal APIs, including:
    • Encoder.encode uses @overload to distinguish return_offset=True → int from the default → bytes
    • A TreeChild alias expressing SearchTreeNode's "node | leaf | empty" child states
    • Filled-in generic parameters (dict[str, Any], list[Any], etc.)
  • Fixed latent typing issues: languages=NoneOptional[...], int_type/float_type literal widening, bits_rstrip default value.
  • CI type checking: added pyright to the dev deps with a [tool.pyright] config (standard / pythonVersion 3.9), and a Type check step in both the CI and publish workflows.
  • Version bumped to 0.2.7.

Verification

Check Result
pyright (standard, py3.9) 0 errors, 0 warnings
ruff check + format --check passing
pytest tests/test_api.py 6 passed
wheel / sdist include py.typed ✅ (flit picks it up automatically)

Verified in a clean venv with the built wheel installed: the Pylance/pyright reportMissingTypeStubs warning is gone, and reveal_type shows the full signatures.

🤖 Generated with Claude Code

Convert the single-module distribution into a package and ship a PEP 561
py.typed marker so type checkers (Pylance/pyright) pick up the inline type
hints, resolving the reportMissingTypeStubs warning reported in #18.

- mmdb_writer.py -> mmdb_writer/__init__.py + py.typed marker
- Add complete type annotations across public and internal APIs
  (overloaded Encoder.encode, TreeChild alias, generic params, etc.)
- Fix latent typing issues: languages default, int/float_type literal
  widening, bits_rstrip default
- Add pyright to dev deps with [tool.pyright] config (standard, py3.9)
- Run pyright as a Type check step in CI and publish workflows
- Bump version to 0.2.7

Closes #18

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vimt vimt merged commit 806a76e into master Jun 1, 2026
5 checks passed
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.

Add typing on library

1 participant