Skip to content

chore(lint): fix B023 and B905 and widen Ruff include per package - #241

Merged
lanyue-llk merged 3 commits into
mainfrom
chore/lint-bugbear-and-include
Nov 4, 2026
Merged

lanyue-llk merged 3 commits into
mainfrom
chore/lint-bugbear-and-include

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #89 (as narrowed in its latest comment)

Summary

Fixes B023 and B905 by hand outside hash-bound sources, enforces both in make lint-check, and widens the Ruff include where that needed only small fixes.

B905 (78 fixed). 74 are strict=True: the lengths are equal by construction or already checked. 4 are strict=False: zip(x, x[1:]), which is pairwise and differs in length on purpose.

B023 (60 fixed). Each closure now binds the loop values it uses through a default argument, so rendering does not change. The one exception is the real bug below, which is fixed by a rename.

Real bugs: one report crash, one small validator gap.

  • generate_webmainbench defined a local scope() function, then rebound scope to the anomaly review's dict inside the language loop. h calls scope(), so rendering with an anomaly_review raised TypeError: 'dict' object is not callable in both language modes on main. build_webmainbench_report always passes one, and no test or golden did. The dict is now anomaly_scope, and test_anomaly_review_renders_in_both_languages covers both languages.
  • No other closure outlives its iteration. An AST pass over the 52 name=name defaults added here looked for a rebinding after the closure's definition. Its two hits are a comprehension variable and a nested function's local, which are different variables.
  • webmainbench_report_check.py checked matched-latency rows with zip(cells[-3:], expected_times). A row with only two cells was compared as far as it went and could pass. strict=True now rejects it.
  • The other strict=True sites add a guard but fix no defect I could show.

Ruff include now also covers: src/harness/benchmarks, lexbench, reporting, web_search, the 14 top-level src/harness/*.py modules, scripts/ and examples/.

  • Small fixes: import sorting and pyupgrade autofixes, plus seven hand fixes (E701, E731, and B904 with from error).
  • Long lines are ignored per package rather than rewrapped. Scripts also ignore E402 because they insert src/ on sys.path before importing it.
  • make lint-check gains B023,B905 in its repo-wide pass, so packages outside include keep these two rules.

Left out

Hash-bound files, byte-identical in this PR. Findings are suppressed through per-file ignores where needed:

Binding Files
SCORING_SOURCE_FILES, code-migration after_sha256 src/lexbench_webfetch/* (14 B023 and 16 B905 left)
Search scoring_source_sha256, code-migration src/lexbench_websearch/* (1 B905 left)
worker_sha256 web_fetch/providers/headless_worker.py
runner_sha256 web_fetch/webmainbench_runner.py, webmainbench_latency_diagnostic.py (1 B905 left), webmainbench_latency_correction.py (2 B905 left)
cohort_reference_hashes trajectory_replay/{remote_execution,webarena_replay,retrieval_acceptance,webarena_corrections,remote_runtime}.py, scripts/run_remote_three_method_cohort.py
Copied into reports or protocols lexbench/reproduction.py, the chart module copied beside it, lexbench/resource_matrix.py, lexbench/resource_profiles.py (I001 left)
Search collection_implementation web_search/{runner,core,profiles}.py (I001 left), web_fetch/config.py, env_file.py, record_io.py, distribution.py, benchmarks/data.py
Visual receipts reporting/visual.py (I001 left), web_search/visual.py (2 B023 and I001 left), web_search/pages.py, trajectory_replay/webarena_report_visual.py
Native route baseline web_fetch/native_projection.py

The 36 B023 and B905 findings left in these files were not audited for real bugs.

Packages left out of include because they need a large rewrite. Approximate findings, not counting E501:

  • src/harness/web_fetch: about 860, mostly one-line E701/E702 statements.
  • tests/*.py: about 1,290.
  • tests/benchmarks: about 230.
  • tests/web_search: about 120.
  • .agents: one skill script with 18.
  • src/lexbench_webfetch, src/lexbench_websearch: hash-bound.

All of these stay under F, TID252, B023 and B905, apart from the per-file ignores above.

Hash effects to check.

  • pyproject.toml is part of Search collection_implementation, so a Search cohort in flight cannot resume across this commit. That is true of any pyproject.toml change.
  • web_fetch/ edits change runtime_source_sha256 for future runs only. It is compared between batches of one run, not against the current tree.
  • Edits to webmainbench_diagnostics.py and rescoring.py change the source hash recorded in future audits. I found no code that compares a stored value with the current file.

Golden changes

tests/golden/web-search.json: only the manifest.json route changes. Diffing the normalized builds shows the single changed field is renderer_sha256, because web_search/report.py was edited (import sort, UP034). All other routes and all other goldens are unchanged.

Test plan

  • After restoring annotation_revisions.py and rebasing on the newest main: the lint gate, tests/test_golden_reports.py and tests/test_webmainbench_report.py pass (31 passed), goldens unchanged. The results below were not rerun for that commit.
  • After the scope fix: tests/test_webmainbench_report.py and tests/test_golden_reports.py: 31 passed, goldens unchanged. The new test fails with the TypeError when the fix is removed. The results below were not rerun for that commit.
  • Lint: ruff check --config 'include=["*.py"]' --select F,TID252,B023,B905 ., the same command with F,TID252, and ruff check all pass.
  • In the worktree: tests/test_golden_reports.py, tests/test_lexbench_cli.py and tests/test_lexbench_report_runtime.py: 62 passed.
  • Full suite on a copy of the tree outside the checkout (-n 2), run before the last edit that restored the two latency files to their base bytes: 20021 passed, 28 failed, 1 collection error.
    • 14 failures are on the known local-failure list.
    • 12 failures and the collection error also fail on a clean export of the base commit: test_optional_reports (3), test_packaging_hygiene (1), test_public_tree_privacy (1), test_report_software_versions (1), test_hf_inputs (1), test_run_webarena_catalog (5) and the public_webarena/test_diagnostics.py import error.
    • 2 failures did not reproduce: test_lexbench_cli::test_maintained_template_supplies_every_file_the_report_copies and test_lexbench_report_runtime::test_template_source_without_the_template_stops_before_reading_evidence[profile]. Both pass in the worktree. In the copy, the first failed because scripts/moli_report existed there; that directory is not on this branch. I did not find what created it or why the second failed there.
  • In the worktree, 4 test_network_preflight.py failures are local only: the worktree sits inside an older checkout whose evaluation/lexbench-webfetch.json is found by the parent-directory walk. They do not occur in the copy or on the base export.
  • CI is the full-suite gate.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 45c7e11

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 1

Reviewed head 45c7e117 against main at 8f2232b7.

Findings

P1: src/harness/web_fetch/report.py:3363 and :3526. A real late-binding bug is only half fixed, and the PR says none exists.

generate_webmainbench defines the local function scope(text) at line 3326. Inside the for english loop, line 3526 rebinds the same name to a dict: scope=anomaly_review['scope']. This is what B023 flagged on h. build_webmainbench_report loads research/webmainbench-anomaly-review.json and always passes it, so the branch runs on every real build.

I rendered sample_report_inputs with anomaly_review={'cases':[],'scope':{'signal_triggered_results':0,'distinct_cases':0}}:

Commit include_english=False include_english=True
Base 8f2232b7 TypeError: 'dict' object is not callable (report.py:3528, the next h() call) same TypeError at 3528
Head 45c7e117 passes TypeError: 'dict' object is not callable (report.py:3364, first h() of the English pass)

The new default h=lambda zh,en,scope=scope,english=english:... keeps the function for the first pass. On the second pass it captures the dict left behind by the first pass, so the English build still crashes. No test or golden passes anomaly_review to this function, so CI stays green.

This also contradicts the PR body: "Real bugs: no late-binding bug" and "behavior does not change". The issue asks for each real bug to be named.

Suggested fix:

  • Rename the dict local to anomaly_scope at line 3526 and at its two uses in the f-strings at line 3528.
  • Restore h=lambda zh,en:scope(en if english else zh), or keep only english=english if B023 still needs it.
  • Add one test that calls generate_webmainbench with anomaly_review and include_english=True.
  • Name this bug in the PR body's real-bugs list.

Verified, no defect found

  • Lint: all three gates pass on the head: F,TID252, F,TID252,B023,B905 and plain ruff check. The diff adds no noqa.
  • strict= counts: 74 strict=True and 5 strict=False in the added lines, matching the PR body.
  • strict=True sites in src/: I read each one. Lengths are equal by construction, or guarded by an earlier length check or len()==len() short-circuit, or the site is already inside a validator that raises ValueError. The evidence-compare zip at report_explainer.py:773 has exactly two article panes.
  • strict=False sites: all are pairwise zip(x, x[1:]).
  • Other B023 default-argument sites in src/: I found no other rebinding between definition and call, and no caller passes an extra positional argument. This includes re.sub callbacks, page.on('pageerror', ...) (one event argument) and the checker(case, binding) call in rescoring.py.
  • Other helper swaps: socket.timeout is an alias of TimeoutError on Python 3.11, and the lambda to def conversions and import moves are equivalent.
  • Hash-bound files: every listed file is byte-identical. The only src/lexbench_webfetch edit is annotation_revisions.py, which is not in SCORING_SOURCE_FILES or code-migration.json. The base SHA-256 of none of the 110 changed files appears in any tracked file, or in the local evidence JSON sampled (first 20,000 files under 2 MB; that search had a time limit, so it may not have finished).
  • Golden snapshots: only the manifest.json route of tests/golden/web-search.json changes, as explained in the PR.
  • Local tests: test_golden_reports, test_webmainbench_report, test_lexbench_cli, test_lexbench_report_runtime and test_public_report_language: 120 passed.
  • Scope of Closes #89: the narrowed scope is otherwise met. The left-out packages are listed with reasons, and make lint-check enforces B023 and B905 across the repository.
  • Over-design: nothing to report.
  • CI: all checks on the head pass, including "Tests and static checks" and "Installation and packaging".

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Round 1 review:

Fixed: the scope shadowing crash in generate_webmainbench (bb34743). The anomaly review's dict rebound the local scope() helper, so rendering with an anomaly_review raised TypeError. The dict is now anomaly_scope, and the scope=scope default is gone. test_anomaly_review_renders_in_both_languages covers both languages and fails without the fix. The PR body now lists this bug under real bugs.

Disputed: nothing.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · bb34743

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 1

Reviewed head bb347432 against main at 8f2232b7. This includes the fix for the scope crash reported in the earlier review of 45c7e117. I also did a trial merge with the latest main (23239677).

No P0, P1 or P2 defects found.

Findings

P3: src/lexbench_webfetch/annotation_revisions.py:123. This one-line edit has no effect on lint.

The PR adds B905 to the per-file ignore for src/lexbench_webfetch/*.py, so this strict=False isn't needed to pass the gate. It is also the only edit in a package the PR otherwise leaves out, while 15 other B905 findings there stay in place. The behaviour is unchanged, and the edit is disclosed in the PR body. The file isn't in SCORING_SOURCE_FILES or code-migration.json, and PR #239 doesn't change it.

Suggested fix: revert the line and drop the matching note from the "Left out" table, so the package has no edits. This is optional.

Verified

  • scope fix: test_anomaly_review_renders_in_both_languages fails with TypeError on the report.py from both 8f2232b7 and 45c7e117, and passes on the head. scope is no longer rebound in generate_webmainbench.
  • Lint: F,TID252, F,TID252,B023,B905 and plain ruff check all pass. An isolated B023,B905 run finds 35 findings (16 B023, 19 B905), all in the listed hash-bound files. This matches the PR body's counts.
  • strict=True in src/: I read every site. Each has equal lengths by construction, or an earlier length check or equivalent guard, so none adds a new failure on valid input. The one changed outcome is the matched-latency check in webmainbench_report_check.py:810, which now rejects a row with too few cells. This matches the gap the PR describes.
  • strict=False: all are pairwise zip(x, x[1:]).
  • B023 default arguments: an AST pass over every closure changed in src/ and tests/ found that each bound name has one assignment, made before the closure, so there is no stale or unbound capture. The rescoring.py lambda is called within its iteration. page.on('pageerror', ...) receives one event argument.
  • Other changes: socket.timeout is an alias of TimeoutError on Python 3.11. The lambda to def conversions, the import moves and the removed sum parentheses are equivalent.
  • Hash bindings:
    • Every file named in the "Left out" table, including lexbench/charts.py, is byte-identical to the base, except annotation_revisions.py as disclosed.
    • The only src/lexbench_* change is the line above.
    • I read the source-hash code in collection_implementation, capture_source_identity, rescoring.py and renderer_sha256. The PR's description of the hash effects holds for the ones it lists.
    • No tracked file contains the base SHA-256 of a changed file.
    • The entries in research/initial-reference-audit.json for scripts/audit_initial_references.py were already stale on the base, so this PR did not cause that.
    • I did not scan local evidence, so this covers tracked files and code only.
  • Coverage claims: every top-level src/harness/*.py module is now covered. The left-out list matches the tree, apart from setup.py, which is trivial.
  • Golden snapshots: only the manifest.json route of tests/golden/web-search.json changes, as the PR explains. I did not repeat the normalized build diff for the claim that renderer_sha256 is the single changed field.
  • Local tests on the head: test_golden_reports, test_webmainbench_report, test_public_report_language, test_network_preflight, test_headless_review, test_result_review, test_run_certified_benchmark and web_search/test_runner: 174 passed.
  • Trial merge with 23239677: no conflicts, all three lint gates pass and the goldens pass (17 passed).
  • Scope of Closes #89: it matches the issue as narrowed in its latest comment.
  • Over-design: the PR adds no new abstraction. The per-package ignores are configuration only.
  • CI: all checks on bb347432 pass, including "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks".

@lanyue-llk
lanyue-llk force-pushed the chore/lint-bugbear-and-include branch from bb34743 to 257d093 Compare November 4, 2026 12:32
@lanyue-llk

lanyue-llk commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixes for review round 1:

  • Fixed the P3: src/lexbench_webfetch/annotation_revisions.py is back to its base bytes (257d093), so src/lexbench_webfetch has no edits in this PR. The strict=False had no lint effect under the per-file ignore. The PR body counts are updated: B905 fixed is now 78, with 16 B905 left in that package and 36 B023 and B905 findings left overall.
  • Rebased on the newest main. No test was added because behaviour is unchanged.
  • Nothing disputed.

Locally the lint gate, tests/test_golden_reports.py and tests/test_webmainbench_report.py pass, and goldens are unchanged. CI on the new head is pending.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 257d093

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 2

Reviewed head 257d0935 against base 23239677. No defects found.

Round 1's P3 is resolved: src/lexbench_webfetch/annotation_revisions.py is back to its base bytes, and the PR no longer touches src/lexbench_webfetch.

What I verified

strict=True sites. I read the context of each site in src/harness. Each one has equal lengths by construction, or an explicit length or identity check before the zip. In the report.py audit inventory, the rows are built per change. Both templates behind report_explainer.py's .evidence-compare emit exactly two articles. The WebMainBench matched-latency check is the one site where the guard is new, as the PR body says.

strict=False sites. The source sites are pairwise zip(x, x[1:]).

B023 default bindings. An AST pass over the self-named defaults added in changed files found:

  • every name is bound before its closure's definition, so none can raise NameError when the closure is defined;
  • two names are rebound later. report_capabilities.py:120 row is rebound only by a comprehension variable, and the tests/benchmarks/test_pinning.py:381 hit was not read beyond the AST result;
  • callers pass only the original arguments. The re.sub callback and the Playwright pageerror handler take one argument, so the extra default does not change the call.

anomaly_scope fix. Reverting the rename makes test_anomaly_review_renders_in_both_languages fail, so the test exercises the bug.

Other changes. socket.timeout is an alias of TimeoutError on Python 3.11, so removing it changes nothing. The E731 rewrites and the from error change keep the same behaviour.

Hash-bound sources.

  • None of the sources I checked from the PR's table appear in the diff, including SCORING_SOURCE_FILES, collection_implementation, cohort_reference_hashes, the worker and runner hashes, and the native and visual sources.
  • The base SHA-256 of every changed file appears nowhere in the tracked tree, so no committed binding moves.
  • research/initial-reference-audit.json names scripts/audit_initial_references.py, which this PR edits. Its stored hash already differed from the base bytes, and no code reads that file, so the PR breaks nothing there.

Counts and lint.

  • ruff --isolated --select B023,B905 reports 36 findings (20 B905, 16 B023), split across files as the PR body says.
  • ruff check --config 'include=["*.py"]' --select F,TID252,B023,B905 . and ruff check both pass.
  • make ci-tests runs lint-check, so CI enforces the new rules.

Tests. tests/test_golden_reports.py and tests/test_webmainbench_report.py pass locally (31 passed), with goldens unchanged and the tree clean. I did not run the full suite locally. The only golden changed is the web-search manifest.json route, and I did not separately re-diff it.

Scope. Closes #89 matches the issue's narrowing comment.

CI. All checks pass on this head: Tests and static checks, Installation and packaging, Rendered reference and report checks. main has moved to d905949c since the base, and GitHub reports the PR as mergeable. CI has not run against that newer main.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
Bind every loop-variable closure and make every zip explicit outside hash-bound
sources, and enforce both repo-wide in lint-check. Widen the Ruff include to the
benchmarks, lexbench, reporting and web_search packages, the top-level harness
modules, scripts and examples. Hash-bound sources stay byte-identical through
per-file ignores.
…e helper

generate_webmainbench rebound its local scope() function to the anomaly
review's scope dict inside the language loop, so rendering with an anomaly
review raised TypeError. Name the dict anomaly_scope and test it in both
languages.
@lanyue-llk
lanyue-llk force-pushed the chore/lint-bugbear-and-include branch from 257d093 to ca885b7 Compare November 4, 2026 13:24

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · ca885b7

No findings in this review.

@lanyue-llk
lanyue-llk merged commit 43b149a into main Nov 4, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the chore/lint-bugbear-and-include branch November 4, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend lint coverage to the whole repository and enforce a formatter

1 participant