Repository navigation
Fix the simulation gateway's Pyright errors - #866
Merged
Merged
Conversation
anth-volk
added this pull request to stack #867
October 21, 2026 14:53
This was referenced Oct 21, 2026
anth-volk
force-pushed
the
pyright-gateway
branch
2 times, most recently
from
October 21, 2026 16:59
3a8f700 to
fda7c54
Compare
Each `with runtime.span(...)` in the gateway's endpoints becomes `with scopes.span(runtime, ...)`, which returns the same scope typed as not suppressing exceptions. Pyright no longer reports the variables assigned inside a span as possibly unbound (66 errors), or the handlers that return from inside one as missing a return (6). The gateway's baseline drops from 81 entries to 9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two argument types Pyright rejected, with no behaviour change: - The budget-window submit response passed the seed state's status, typed as any batch status, where the response accepts only "submitted". A new batch's seed state is always created submitted and storing it doesn't change it, so the response now says "submitted". - `_version_map_from_state` took a VersionRoutingState TypedDict, but callers pass the plain dict read from the routing-state Modal Dict, and the helpers it calls take a dict and check each field's type. It now takes a dict, and the TypedDict, used nowhere else, is gone. The gateway's baseline drops from 9 entries to 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The in-image smoke listed `METHOD path` for every route with a `methods` attribute, which Pyright can't narrow from BaseRoute, so it rejected `route.methods` and `route.path`. It now keeps the routes that are Starlette Routes (FastAPI's APIRoute is one) with methods. For the gateway app that is the same 12 routes as before. The gateway's baseline is now empty: no Pyright errors remain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
pyright-gateway
branch
from
October 21, 2026 20:33
fda7c54 to
5a85d53
Compare
anth-volk
marked this pull request as ready for review
October 21, 2026 21:36
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.
Fixes #865
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
Second in the Pyright stack, on top of #864. Fixes all 81 of the simulation gateway's Pyright errors without changing behaviour. The gateway's baseline (
rules/baselines/pyright-gateway.txt) goes from 81 entries to 0; the stack's top PR deletes it and makessim.quality.pyright-gatewayenforced.What changed
with runtime.span(...)blocks inendpoints.pybecomeswith scopes.span(runtime, ...)(Run Pyright in CI for every package, in its own locked environment #864's helper). It returns the same scope object, typed as not suppressing exceptions, so Pyright no longer reports the 66 variables assigned inside a span as possibly unbound, or the 6 handlers that return from inside one as missing a return.seed_state.status(any batch status) whereBudgetWindowBatchSubmitResponse.statusaccepts only"submitted". A new batch's seed state is always createdsubmitted(create_initial_batch_state), and storing it (put_batch_job_seed) doesn't change it, so the response now says"submitted"._version_map_from_statewas annotated with aVersionRoutingStateTypedDict, but its callers pass the plaindictread from the routing-state Modal Dict, and the helpers it calls (_routing_state_routes,_routing_state_latest) take adictand check each field's type. It now takes adict, and the TypedDict, which nothing else used, is removed.hasattr(route, "methods")doesn't narrow Starlette'sBaseRoute, so Pyright rejectedroute.methodsandroute.path. The smoke now keeps routes that are StarletteRoutes (FastAPI'sAPIRouteis one) with methods. For the gateway app this is the same 12METHOD pathroutes as before (checked by building the app both ways).Commits (red, then green)
Each red is the Pyright check against the baseline with that commit's entries removed, run on the code before the fix.
Suppressions added
None.
Real bugs found
None.
Self-review
review-codeon this PR's diff, run by a separate agent, found no bugs. Code-quality findings, all declined:Mapping[str, object]instead ofdict. Declined:_version_map_from_statenow takes the samedictthe module's_routing_state_*helpers already take. Changing them all is a separate refactor of the module's routing-state typing.Environment variables
No CI, image or deployment configuration changes.
smoke_app.pyruns in the Modal image smoke; it now importsstarlette.routing.Routeat module level, which the gateway environment and image already install with FastAPI. It reads no new environment variables.Testing
python -m scripts.rules pyright projects/policyengine-simulation-gateway: passes with 0 errors.This PR is above the bottom of a stack, so its CI runs only
CI complete, which fails by design until #864 merges and this PR is rebased ontomain.🤖 Generated with Claude Code