Repository navigation
Conversation
anth-volk
added this pull request to stack #867
October 21, 2026 15:11
This was referenced Oct 21, 2026
anth-volk
force-pushed
the
pyright-executor-runtime
branch
3 times, most recently
from
October 21, 2026 16:59
3724c77 to
53cea05
Compare
The annual simulation's nine spans in simulation_runtime.py now use scopes.span, so Pyright no longer reports the 47 variables assigned inside a span as possibly unbound. With baseline and reform bound, Pyright then reports that a Simulation can't be passed to _report_calculation_start, which takes a StageReportingSimulation (the 2 errors were already baselined as "Unbound | Simulation"). _build_simulation returns one in both branches (ArtifactBaselineSimulation subclasses it), and _report_calculation_start relies on that by calling on_first_ensure, so its return annotation now says StageReportingSimulation. The executor's baseline drops from 126 entries to 77. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The last 5 Pyright errors in simulation_runtime.py, without changing what a run does: - _compile_interval_policy: compile_reform returns None only for an empty policy, which the function has already returned, so a None result now returns the policy unchanged instead of failing on .items(). - _build_uk_weight_replacement_region checks the region prefix against a tuple instead of a set display. A set display is typed set[str], so the check didn't narrow prefix to the two UK region types Region accepts; the tuple keeps their literal types. - The UK weight-matrix check counts households from the input dataset's entity_data, which Dataset types as an optional BaseModel. It now reads entity_data with getattr and requires a dict, raising TypeError with the dataset's name when none is loaded; a loaded dataset counts the same households. - _build_simulation reassigned its `policy: dict | None` parameter to the compiled policy, which may be a Policy; the result now has its own name, runtime_policy, used where the reassigned name was. The executor's baseline drops from 77 entries to 72. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
pyright-executor-runtime
branch
from
October 21, 2026 20:33
53cea05 to
75b2e5a
Compare
This branch has not been deployed
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 #870
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
Fourth in the Pyright stack, on top of #869. Fixes all 54 Pyright errors in the executor's
simulation_runtime.pywithout changing what a run does. The executor's baseline goes from 126 entries to 72.No
scopes.operationhelper was needed: this module opens only spans.What changed
runtime.span(...)scopes becomescopes.span(runtime, ...), including the credential-setup span chosen by a conditional expression, for consistency (Pyright didn't flag that one). That removes the 47 possibly-unbound errors._build_simulation's return type. Withbaselineandreformbound, Pyright reported that aSimulationcan't be passed to_report_calculation_start, which takes aStageReportingSimulation(the 2 errors were already baselined, wordedUnbound | Simulation)._build_simulationreturns one in both branches (ArtifactBaselineSimulationsubclasses it), and_report_calculation_startrelies on that by callingon_first_ensure, so the return annotation now saysStageReportingSimulation. The unusedSimulationimport goes.compile_reformreturnsNoneonly for an empty policy, which_compile_interval_policyhas already returned unchanged. ANoneresult now returns the policy too (unreachable), as policyengine's own_reform_dict_to_parameter_valuesdoes.prefix not in {"constituency", "local_authority"}didn't narrowprefix, because a set display is typedset[str]. A tuple keeps the literal types, soprefixnarrows to the two valuesRegion.region_typeaccepts.dataset.data.entity_data, but policyengine typesDataset.dataasBaseModel | None. It now readsentity_datawithgetattr(..., None)and requires adict, raisingTypeErrorwith the dataset's name when none is loaded; before, that case raisedAttributeError. A loaded dataset counts the same households. Narrowing on the value, rather thanisinstance(..., UKYearData), keeps the existing tests'SimpleNamespacedatasets valid. It also needs no new import into a module that keeps policyengine out of its module-level imports._build_simulationreassigned itspolicy: dict | Noneparameter to_compile_interval_policy's result, which may be aPolicy. The result now has its own name,runtime_policy, used in the three places that read the reassigned name.The microdata weight checks (
sim.microdata.*) recognise weighted frames by expressions such as<simulation>.output_dataset.data.<entity>. The dataset read changed here is the input dataset (dataset.data), which they don't track, before and after;test_microdata_weight_boundaries.pypasses.Commits (red, then green)
test_uk_weight_matrix_guard.py.Suppressions added
None.
Real bugs found
None.
Self-review
review-codeon this PR's diff, run by a separate agent, found no bugs and no material code-quality issues. It confirmed:It noted that the new
TypeErrorfor an input dataset with no entity data is untested, and that a dataset loaded from a file can't reach it. #873 switches that check to the sharedEntityFramesprotocol.Environment variables
No CI, image or deployment configuration changes, and no new environment-variable reads.
simulation_runtime.pyruns in the Modal simulation workers; it now importspolicyengine_simulation_observability.scopes(#864), part of the observability library the images already install.Testing
python -m scripts.rules pyright projects/policyengine-simulation-executor: passes with 72.This PR is above the bottom of the stack, so its CI runs only
CI complete, which fails by design until the PRs below merge.🤖 Generated with Claude Code