Skip to content

Fix mypy type errors exposed by py.typed marker#152

Merged
indykoning merged 2 commits into
indykoning:masterfrom
johanzander:fix-mypy-type-errors
Jun 7, 2026
Merged

Fix mypy type errors exposed by py.typed marker#152
indykoning merged 2 commits into
indykoning:masterfrom
johanzander:fix-mypy-type-errors

Conversation

@johanzander

@johanzander johanzander commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

What was fixed

Category Count Fix
dict[str, object] inference in params dicts 8 Explicit dict[str, str | int] annotations
union-attr / operator on Optional dates 8 Simplified None-narrowing with sequential if
dict-item in dict unpacking with union types 3 Proper isinstance narrowing with else branch
override (V1 API intentionally changes signatures) 3 # type: ignore[override]
dict-item for session hooks 1 Wrap hook function in list
return-value for process_response 1 Return type Any (.get() can return None)
arg-type for mode_names.get(None) 1 Guard against None key

CI workflow

Added .github/workflows/mypy.yml — runs mypy --ignore-missing-imports on every push and PR, matching the existing ruff workflow. This ensures the py.typed marker remains meaningful by keeping the package mypy-clean.

Why this matters

PR #147 added the PEP 561 py.typed marker, 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 shipping py.typed at all.

Test plan

  • mypy --ignore-missing-imports passes with 0 errors (was 30)
  • ruff check passes
  • Runtime smoke test — all imports, instantiation, and hash_password work correctly
  • No public API changes — all fixes are internal

🤖 Generated with Claude Code

johanzander and others added 2 commits June 4, 2026 07:10
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>
@johanzander johanzander marked this pull request as draft June 4, 2026 05:13
@johanzander johanzander marked this pull request as ready for review June 4, 2026 05:18
@johanzander

Copy link
Copy Markdown
Collaborator Author

another typing improvement @indykoning, building on #147

@indykoning indykoning left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@indykoning indykoning merged commit fa8c182 into indykoning:master Jun 7, 2026
2 checks passed
@johanzander johanzander deleted the fix-mypy-type-errors branch June 7, 2026 12:10
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