chore: strengthen Python static analysis - #1324
Open
AlexStocks wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens the project’s static-analysis gate by tightening ty and Ruff configurations, wiring ty into the pre-commit/prek workflow, and making production code changes required to satisfy the stricter diagnostics (notably explicit @override usage and statically definite initialization in tracing-related paths).
Changes:
- Enabled additional
tyrule checks and Ruff lint families (ASYNC,DTZ,LOG,PLE) viapyproject.toml, with targeted test-only exceptions. - Moved
ty checkinto prek/pre-commit (and removed the duplicatemake checkinvocation), plus updated harness checking for a Python 3.12 minimum where applicable. - Added
typing-extensionsdependency and applied@overrideacross multiple inheritance boundaries; adjusted client span and memory-search tracing state to be statically definite.
Reviewed changes
Copilot reviewed 22 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Adds typing-extensions runtime dep; configures ty rules/overrides and expands Ruff lint selection. |
.pre-commit-config.yaml |
Adds a local ty check hook executed via uv run --locked. |
Makefile |
Removes standalone ty run from check; pins Bub harness ty invocation to Python 3.12. |
uv.lock |
Locks in typing-extensions as a direct dependency. |
src/powercontext/client/client.py |
Makes request spans start before try to ensure definite initialization for error paths. |
src/powercontext/builtin/runtime/application.py |
Ensures tracing attributes use a definitely-initialized search_mode. |
src/powercontext/builtin/runtime/composition.py |
Adds @override on projector methods crossing inheritance boundaries. |
src/powercontext/builtin/handoff_report/catalog_store.py |
Adds @override on CatalogPage.__repr__/__eq__. |
src/powercontext/server/access.py |
Adds @override to MCP middleware on_request. |
src/powercontext/server/logging.py |
Adds @override to logging filter/formatter overrides. |
src/powercontext/server/mcp.py |
Adds @override to httpx.ASGITransport.handle_async_request. |
src/powercontext/server/metrics.py |
Adds @override to MCP metrics middleware on_request. |
src/powercontext/server/tracing.py |
Adds @override to tracer/middleware overrides for stricter static checking. |
tests/test_handoff_report_models.py |
Adds a scoped DTZ001 ignore for intentional invalid datetime input in tests. |
tests/builtin/runtime/test_scheduler.py |
Tightens PowerContext generics in test helper types. |
tests/integrations/test_hermes_provider.py |
Adds explicit Any typing for stricter type checking in fakes. |
tests/e2e/real_experience_skill/harness.py |
Makes configured-journey state statically definite; documents intentional ASYNC lint exception. |
integrations/hermes/plugins/powercontext/client.py |
Introduces a type-check-only override import with a runtime no-op fallback for compatibility. |
integrations/codex/plugins/powercontext/pyproject.toml |
Adds typing-extensions dependency for the Codex plugin package. |
integrations/codex/plugins/powercontext/uv.lock |
Updates plugin lockfile to include typing-extensions. |
integrations/codex/plugins/powercontext/settings.py |
Adds @override for settings source hooks/customization points. |
integrations/codex/plugins/powercontext/hooks/recall.py |
Adds @override for redirect handler override. |
integrations/claude-code/plugins/powercontext/hooks/user_prompt_submit.py |
Adds type-check-only override import with runtime no-op fallback and uses it on redirect handler override. |
e2e/bub/uv.lock |
Locks in typing-extensions for the Bub harness environment. |
e2e/bub/src/powercontext_e2e/harbor_agent.py |
Uses typing.override (Py3.12+) for Bub harness agent method override. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Which issue or RFC does this PR close?
N/A — this is a focused engineering-hardening change with no linked issue or RFC.
Rationale for this change
The default
tyconfiguration leaves several high-value diagnostics disabled. Enabling them against the production source exposed missing override declarations and control-flow paths whose variables were not provably initialized. Those gaps reduce refactor safety and delay feedback until runtime or review.This change makes the validated rules part of the normal development gate while keeping the scope limited to static safety. It does not change the public HTTP contract, persisted formats, or PowerContext domain behavior.
What changes are included in this PR?
tyrules for possible unresolved references, missing override declarations, raw generics, optional imports/attributes, dynamic bases, and division by zero;tyfrom prek withuv run --locked, and remove the duplicatetyinvocation frommake check;@overridedeclarations across production inheritance boundaries;ASYNC,DTZ,LOG, andPLErule families;typing-extensionsruntime dependency directly whereoverrideis imported;Tests only received type annotations or explicit initialization needed by the stricter checker; no assertions or observable test scenarios were changed.
Are there any user-facing changes?
No. There are no public API, HTTP/MCP contract, configuration, persistence, or migration changes.
How was this change tested?
make checkmake contract-test— 29 passeduv run --locked ty check --error all src/powercontext integrations/claude-code integrations/codex integrations/hermesmake harness-syncmake harness-check— 6 passedmake unit-testunder Linux/WSL Python 3.13 — 593 passed, 1 skippedmake e2e-testunder Linux/WSL Python 3.13 — 45 passed, 12 skippedgit diff --check origin/master...HEADReal Codex/provider E2E remains opt-in and was not part of the acceptance gate for this static-analysis change.
AI usage statement
OpenAI Codex (GPT-5) was used to inspect the repository, implement the change, run validation, and prepare this PR. A separate read-only Codex review pass checked the final diff before publication.