Add local type stubs for lzf so mypy actually checks its usage - #86
Merged
Merged
Conversation
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.
Contributor
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
python-neo-lzf(thelzfmodule used forbinary_compressedencoding) has nopy.typedmarker and no stubs, somypy'signore_missing_importswas silently treating everylzf.compress()/lzf.decompress()call asAny-- no argument or return type was ever actually being checked.stubs/lzf-stubs) covering just the two functions pypcd4 calls, and wire it up as a local editable dev dependency via[tool.uv.sources].mypyruns against pypcd4's own source (dev dependency, not shipped to users) -- it doesn't give downstream callers oflzfany type checking of their own.Test plan
reveal_type()onlzf.compress's result shows the real type instead ofAnyintinstead ofbytes) intolzf.compress(...)and confirmedmypyfails with a precisearg-typeerror at the exact line, then reverteduv sync --all-extras --devinstallslzf-stubscleanly across Python 3.8 through 3.14mypy src/ruff check src/pytest-- all pass