Skip to content

Add local type stubs for lzf so mypy actually checks its usage - #86

Merged
urasakikeisuke merged 1 commit into
mainfrom
chore/add-lzf-type-stubs
Sep 18, 2026
Merged

urasakikeisuke merged 1 commit into
mainfrom
chore/add-lzf-type-stubs

Conversation

@urasakikeisuke

Copy link
Copy Markdown
Collaborator

Summary

  • python-neo-lzf (the lzf module used for binary_compressed encoding) has no py.typed marker and no stubs, so mypy's ignore_missing_imports was silently treating every lzf.compress()/lzf.decompress() call as Any -- no argument or return type was ever actually being checked.
  • Add a minimal PEP 561 stub-only package (stubs/lzf-stubs) covering just the two functions pypcd4 calls, and wire it up as a local editable dev dependency via [tool.uv.sources].
  • This only affects mypy runs against pypcd4's own source (dev dependency, not shipped to users) -- it doesn't give downstream callers of lzf any type checking of their own.

Test plan

  • Verified this actually works, not just installs: reveal_type() on lzf.compress's result shows the real type instead of Any
  • Injected a deliberately wrong argument (an int instead of bytes) into lzf.compress(...) and confirmed mypy fails with a precise arg-type error at the exact line, then reverted
  • uv sync --all-extras --dev installs lzf-stubs cleanly across Python 3.8 through 3.14
  • mypy src / ruff check src / pytest -- all pass

python-neo-lzf (the lzf module used for binary_compressed encoding)
has no py.typed marker and no stubs, so mypy's ignore_missing_imports
was silently treating every lzf.compress()/lzf.decompress() call as
Any -- no argument or return type was ever actually being checked.

Add a minimal PEP 561 stub-only package (stubs/lzf-stubs) covering
just the two functions pypcd4 calls, and wire it up as a local
editable dev dependency via [tool.uv.sources]. Verified this
actually works, not just installs: reveal_type() on lzf.compress's
result now shows the real type, and injecting a deliberately wrong
argument (an int instead of bytes) makes mypy fail with a precise
arg-type error instead of silently passing.

This only affects mypy runs against pypcd4's own source (dev
dependency, not shipped to users) -- it doesn't give downstream
callers of lzf any type checking.
@urasakikeisuke
urasakikeisuke requested a review from a team as a code owner September 18, 2026 08:28
@github-actions

Copy link
Copy Markdown
Contributor
Title Coverage Tests Skipped Failures Errors Time
Python 3.8 Coverage 75 1 💤 0 ❌ 0 🔥 1.117s ⏱️
Python 3.9 Coverage 75 1 💤 0 ❌ 0 🔥 1.101s ⏱️
Python 3.10 Coverage 75 1 💤 0 ❌ 0 🔥 1.095s ⏱️
Python 3.11 Coverage 75 1 💤 0 ❌ 0 🔥 1.121s ⏱️
Python 3.12 Coverage 75 1 💤 0 ❌ 0 🔥 1.100s ⏱️
Python 3.13 Coverage 75 1 💤 0 ❌ 0 🔥 1.124s ⏱️
Python 3.14 Coverage 75 1 💤 0 ❌ 0 🔥 1.110s ⏱️

@urasakikeisuke
urasakikeisuke merged commit d58b683 into main Sep 18, 2026
15 checks passed
@urasakikeisuke
urasakikeisuke deleted the chore/add-lzf-type-stubs branch September 18, 2026 08:30
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