chore: fix mypy type checking in local development #43
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.
what
This PR fixes mypy type checking to work consistently in local development environments and CI:
Added null check in
stacklet/mcp/lifespan.py: Added an assertion to ensurectx.request_contextis not None before accessing its attributes (line 51)Added
pipto dev dependencies: mypy requires pip to auto-install type stubs, but uv venvs don't include it by defaultAdded explicit type stub packages: Added
types-cachetools,types-pyyaml, andtypes-requeststo dev dependencies for reproducible builds with pinned type versionswhy
The Problem:
Item "None" of "RequestContext[Any, Any, Request] | None" has no attribute "lifespan_context"Root Cause:
When running mypy in a uv-managed venv without pip, mypy attempts to auto-install type stubs but silently fails. This causes mypy to continue without full type information, resulting in a false positive "Success" even when type errors exist.
The Fix:
This gives us the best of both worlds: reproducible builds with pinned type stubs, plus a safety net if mypy needs to install additional stubs in the future.
testing
Tested the fix by:
uv run pre-commit run --all-files- all checks passedAll pre-commit hooks now pass including:
docs
No user-facing documentation needed. This is an internal development tooling fix.
The inline comments in
pyproject.tomlexplain why pip and type stubs are included in dev dependencies.