Repository navigation
fix(typing): bind sixteen annotation names at module scope - #1207
Conversation
Every module here defers annotation evaluation, so a name the module never binds at module scope costs nothing at import time and nothing in CI. The new test resolves the property statically: annotation names are read out of the AST (string annotations and nested subscripts included) and must be bound at module scope, where get_type_hints resolves them. Module scope only, by construction: a function-local import binds that function's locals, never the module globals. Two controls pin that -- one synthetic, one on async_evolve.py, whose function-local EvolvingArtifact import must not count -- and a TYPE_CHECKING import must count. Fails on main at e43e847 with the 24 rows this issue lists.
Sixteen names over twenty-four annotated objects in twelve modules were never bound at module scope, so resolving any of those annotations raised NameError while the suite stayed green. Nothing here changes runtime behaviour: every module already defers annotation evaluation, and the cross-module names stay behind TYPE_CHECKING because the cycles are why those annotations are strings. Three typing lines gain a name (Union, Optional, Sequence), one existing TYPE_CHECKING block gains CallLimit, seven modules gain a TYPE_CHECKING block, and selection.py takes a plain module-level import random -- stdlib, no cycle.
|
Advisory Verifier report; Verdict: CHANGES REQUESTED Ran:
SummaryImport-only change across 12 modules: The sweep is well built and its red is real: 24 rows at base Blocking
Non-blocking
Risk / mergerisk_gate -> T3 (362 changed lines, 14 files; |
|
Both blocking items from the advisory report are fixed at tip
No code change beyond the fragment wording; the sweep, the two rule controls and the import paths are unchanged. |
|
Advisory Verifier report; Verdict: PASS (advisory) Tip SHA: Ran (fresh clone,
Runtime reach, matching the corrected fragment: Head move: my earlier read at Risk: T3 by path ( Not run:
Findings: none blocking. Record (non-blocking):
No UI surface: import lines, No merge action from QA: this report is advisory, the merge gate is the repo's review decision on the head sha, and the merge itself is executed by the repo's merge process. |
|
Verdict: PASS Ran (fresh clone; base worktree at
Not run:
SummaryFixes #1203. 14 files BlockingNone. Non-blocking
Risk / mergerisk:T3 (14 files, package code). Advisory only: no merge action from QA -- this report is advisory, the merge gate is the repo's review decision on the head sha, and the merge itself is executed by the repo's merge process. No UI surface: typing-import-only change; no CLI, MCP, docs page or rendered UI text changes (the changelog fragment is release text, not a surface). |
|
Review tip: Blocking: none. Both items from
The code is unchanged from Ran at this tip (serial,
Not run: full Non-blocking:
Advisory only: |
|
Review (Birfy) Tip SHA: e3d9475
|
Fixes #1203.
What changed
Sixteen type names were used in this package's annotations but never bound at module scope, so a static reader could not resolve them (the same blind spot as
Tupleinagents.py,#1202). This change binds them, and it is import-only: no annotation text, no signature, no generated API text, no runtime path.Union(agent_society.py),Optional(evaluation.py),Sequence(scheduler.py) join the existingtypingimport lines;selection.pygets a plainimport random(the name is used as a value there, not only in annotations).if TYPE_CHECKING:— seven new blocks (async_evolve.py,audit/wiring.py,budget.py,evolution.py,proofs.py,evolvespec.py,selfplay.py) and one extended (evolve_settings.py):EvolvingArtifact,BudgetSettings,RuntimeSettings,ObservabilitySettings,VerifierBoost,Completion,TrajectoryStore,ParallelStrategy,CallLimit,VersionVector,Invariant,RoundInfo.tests/test_annotation_names.py(306 lines) parses the package withastand fails when an annotation name has no module-scope binding in its own module. It prints every offending row, not just the first per object, and carries two rule controls: a function-local import must not be credited, and aTYPE_CHECKING-only import must be.TYPE_CHECKINGnames — that block does not execute, sotyping.get_type_hints()on those objects still raises. The issue scopes the fix as AST-level for exactly that reason (acceptance 4): roughly fifty pre-existing annotations referenceTYPE_CHECKING-only names, and aget_type_hintstest would stay red after a correct fix and push real runtime imports into the modules that avoid them.Rows (24 sites / 16 names / 12 modules at
main1aa816e0; line numbers move withmain):agent_society.pysociety_evolveUnionasync_evolve.pyasync_evolveEvolvingArtifact,BudgetSettings,RuntimeSettings,ObservabilitySettingsaudit/wiring.pyAudit,attachVerifierBoostbudget.pybudgeted_completionCompletionevaluation.pyEvaluationReportOptionalevolution.py_Runtime,evolveTrajectoryStore;evolvealsoParallelStrategy,CallLimit,BudgetSettings,RuntimeSettings,ObservabilitySettingsevolution.py_record_rolloutVersionVectorevolve_settings.pyBudgetSettingsCallLimitevolvespec.pybuild_call_limit,_limit_from_knobsCallLimitproofs.py__init__Invariantscheduler.pypop_forSequenceselection.py__init__randomselfplay.pyon_roundRoundInfoAll twelve
TYPE_CHECKINGimport paths were checked against the target module at this tip (budget.CallLimit,agents.Completion,evolution.EvolvingArtifact,evolution.RoundInfo,evolvable.VersionVector,parallel.ParallelStrategy,trajectory.TrajectoryStore,invariants.Invariant,audit.boost.VerifierBoost,evolve_settings.BudgetSettings/RuntimeSettings/ObservabilitySettings). The sweep pins names, not paths — a wrong module would need a hand check, and this PR records the one it had.The branch's two commits (
6403221test,691b00ffix) are unchanged; the tip is a plain merge ofmainat1aa816e0(the branch had fallen two merges behind) plus the changelog fragment and its wording fix. No rebase, no force-push.Verification at the tip
Tip SHA:
e3d9475c47cca456e86d8d989b16b00cc8493808Ran:
pytest -q -o addopts='' tests/test_annotation_names.py→3 passed251 passed, 8 warnings1aa816e0→1 failed, 2 passed, printing all 24 rowspython -m tools.gen_api_docs --check→docs/api.md is up to datepython -m tools.changelog_fragments check→15 changelog fragment(s) OKNot run:
pytest -q— the offline suite stalls on this host once the~/.agentdescentrows hit a read-only$HOME; the CI matrix is the linemkdocs build --strict— nodocs/page ormkdocs.ymlchanges in this diffScope
Import lines and
if TYPE_CHECKING:blocks across the twelve modules above, one new test file, onechangelog.d/fragment. No runtime code path, no signature text, no generated docs.