Skip to content

Ship type hints (py.typed), test on Python 3.13/3.14; bump to 1.2.1 - #21

Merged
iskandr merged 1 commit into
masterfrom
types-and-ci
Oct 6, 2026
Merged

iskandr merged 1 commit into
masterfrom
types-and-ci

Conversation

@iskandr

@iskandr iskandr commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #20. No runtime behavior changes.

  • Type hints for the public API, plus a py.typed marker. from_dict, from_json and read_json_file are typed to return the subclass they're called on. I installed the built wheel into a clean venv: mypy and pyright both infer Genome.from_json(...) as Genome, and DataclassSerializable subclasses work the same way.
  • mypy now runs in lint.sh and CI (default strictness, clean).
    • mypy 2 can't target 3.9. The annotations are never evaluated at runtime (from __future__ import annotations), so python_version = "3.10" in [tool.mypy] covers 3.9.
    • lint.sh uses the first of the active virtualenv, .venv or python3 that has mypy, since the active environment may not be this project's (e.g. in a git hook). It still fails if none of them has mypy.
  • Annotations stay usable on 3.9. They use Optional/Union rather than X | Y, so typing.get_type_hints() works on 3.9. This also fixes get_type_hints() on DataclassSerializable subclasses, which already failed on 3.9. tests/test_typing.py covers every annotated class, method and helper; ruff's UP045 is now ignored for the same reason UP007 already was.
  • Python 3.13 and 3.14 added to the CI matrix and classifiers, plus the Typing :: Typed classifier. The suite passes locally on 3.9, 3.13 and 3.14.
  • No new IDE errors downstream. pyright's diagnostics on pyensembl, varcode, sercol, mhctools and vaxrank are identical with 1.1.1 and with this branch.

https://claude.ai/code/session_01JRDMg3F5kNKmnjv5jvQBgr

@coveralls

coveralls commented Oct 6, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 37524288265

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.3%) to 91.322%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 14 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

14 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
helpers.py 11 91.89%
serializable.py 3 94.12%

Coverage Stats

Coverage Status
Relevant Lines: 242
Covered Lines: 221
Line Coverage: 91.32%
Coverage Strength: 0.91 hits per line

💛 - Coveralls

@iskandr
iskandr force-pushed the faster-pickle-and-decode branch from 64891f0 to 5f0f0f0 Compare October 6, 2026 16:56
@iskandr
iskandr force-pushed the types-and-ci branch 2 times, most recently from 36e2dc4 to a970445 Compare October 6, 2026 19:48
@iskandr
iskandr force-pushed the faster-pickle-and-decode branch 2 times, most recently from 57cc43f to c1d173b Compare October 6, 2026 19:52
@iskandr
iskandr changed the base branch from faster-pickle-and-decode to master October 6, 2026 20:08
- Annotate the public API. from_dict / from_json / read_json_file are
  typed to return the subclass they're called on, so mypy and pyright
  infer Genome.from_json(...) as Genome. Ship a py.typed marker.
- Run mypy in lint.sh and CI. lint.sh uses the first of the active
  virtualenv, .venv or python3 that has mypy, since the active
  environment may not be this project's (e.g. in a git hook). mypy 2
  can't target 3.9, but the annotations are never evaluated at runtime,
  so checking as 3.10 is equivalent.
- Use Optional/Union rather than `X | Y` so typing.get_type_hints works
  on Python 3.9; this also fixes get_type_hints on DataclassSerializable
  subclasses, which failed on 3.9 before. Tested by test_typing.py.
- Add Python 3.13 and 3.14 to the CI matrix and classifiers.

No runtime behavior changes.

Claude-Session: https://claude.ai/code/session_01JRDMg3F5kNKmnjv5jvQBgr
@iskandr
iskandr merged commit a69079a into master Oct 6, 2026
8 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.

2 participants