Fix mypy type errors exposed by py.typed marker#152
Merged
Conversation
The PEP 561 py.typed marker (indykoning#147) makes type checkers analyze this package. This fixes all 30 mypy errors that consumers would see: - Annotate params dicts explicitly to avoid dict[str, object] inference - Wrap session.hooks value in list to match expected type - Restructure dict/list union handling with proper isinstance narrowing - Simplify date None-narrowing with sequential if statements - Add type: ignore[override] for intentional V1 API signature changes - Fix process_response return type to Any (response.get can return None) - Guard mode_names.get() against None batt_mode Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Runs mypy on every push and PR, matching the existing ruff workflow. Ensures the py.typed marker remains meaningful by keeping the package mypy-clean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
another typing improvement @indykoning, building on #147 |
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
py.typedis shipped (Add PEP 561 typing to enable static type checking for consumers #147)What was fixed
dict[str, object]inference in params dictsdict[str, str | int]annotationsunion-attr/operatoron Optional datesifdict-itemin dict unpacking with union typesisinstancenarrowing withelsebranchoverride(V1 API intentionally changes signatures)# type: ignore[override]dict-itemfor session hooksreturn-valueforprocess_responseAny(.get()can returnNone)arg-typeformode_names.get(None)NonekeyCI workflow
Added
.github/workflows/mypy.yml— runsmypy --ignore-missing-importson every push and PR, matching the existing ruff workflow. This ensures thepy.typedmarker remains meaningful by keeping the package mypy-clean.Why this matters
PR #147 added the PEP 561
py.typedmarker, which signals to type checkers that this package ships type hints. Without clean types, consumers running mypy see errors from inside the library that they cannot fix — arguably worse than not shippingpy.typedat all.Test plan
mypy --ignore-missing-importspasses with 0 errors (was 30)ruff checkpasses🤖 Generated with Claude Code