Skip to content

fix(python): .filter( is not a comprehension; bitwise string test documents the new rule (red main after #9308) - #9316

Merged
squid-protocol merged 4 commits into
mainfrom
fix-python-strict-keyword-family-tests
Nov 25, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
fix-python-strict-keyword-family-tests

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

What this fixes

Two tests in tests/extraction/languages/test_python_strict.py have been failing on main since #9308 (aef60af, the Python keyword-families commit). Main's own smoke run for that commit is red. I reproduced both on a clean checkout of origin/main. They are separate problems:

1. test_python_comprehensions_was_fixed_from_a_javascript_copy_paste: a real regex bug

#9308 added \b(?:map|filter|reduce|starmap)[ \t]*\( to the comprehensions rule so the functional builtins count. But \b also holds right after a dot, so the method User.objects.filter(active=True) matched. That is exactly the false positive this regression test exists to guard.

Fix (python.py): bare map( / filter( / reduce( / starmap( still count, plus the two qualified forms people actually write, functools.reduce( and itertools.starmap(. A method of anything else (qs.filter(, df.map() no longer does. Only python.py had this pattern (embedded_python and the other languages are unaffected).

2. test_python_bitwise_ops_string_content_still_counts_documented: an intentional change whose test was left behind

#9308 rewrote bitwise_ops so an operator counts only before the first quote on a line (&, ^, << inside a string literal, a C template or a URL query is text). The rule's own comment states the cost: an operator after a string on the same line is missed. The old test still asserted the previous behaviour (re.compile(r"^a~b<<") matching).

Fix (test only): it now documents the new rule: an operator inside a string literal does not count, one before the first quote and a plain flags & 0xFF do.

Needs your eye, not just CI. This narrows the earlier "no string shielding for structural signals" decision (#2535 / #8866). I treated #9308 as the owner's intent because the regex comment is explicit, but if the old rule should stand, the regex has to change instead and this test goes back.

Blessed output moved, so this re-blesses (on main's pin, language-crucible v1.8.0)

  • Both golden-master legs: 90 differences, all comprehension-count and cluster-distance shifts (bless_scope: 0 topological, 90 substantive, 75 in parsed files and 15 in output snapshots). The read-only crucible_check passes both legs afterwards.
  • Family baseline: one cell, python/comprehensions (n_family 177 to 175, recall 0.859 to 0.848). The two family-validity SVGs are regenerated from it (--check passes).

Found while doing this (not changed here)

A full family_oracle_sweep.py on main reports 11 stale cells that this change cannot affect: c (debug_prints, io, panics_and_aborts), go (closures, io, time_date_logic), javascript/time_date_logic, rust (closures, short_circuit) and typescript (io, time_date_logic). They look like earlier engine fixes whose cells were never re-swept (for example rust/closures recall 0.214 on main vs 0.993 now). I left them out so this stays a bug-fix PR; a plain family_oracle_sweep.py --write refreshes them.

Also worth knowing: the sweep's numbers depend on the environment. In a venv with a newer tree-sitter pack the sweep also moves every python cell's function count (4341 to 4334). The committed baseline matches the selfscan venv, which is what I used.

Checks

test_python_strict.py 267 pass; with the family chart / sweep / source-read tests 299 pass; 911 other Python / embedded_python extraction tests pass.

Heads-up for #9307 (the v1.9.0 crucible bump)

That PR hits these same two failures (they are on main) and re-blesses the same golden-master files, so it will need main merged in and one more re-bless after this lands.

🤖 Generated with Claude Code

…ments the new string rule (red main after #9308)

#9308 (aef60af) left two tests in tests/extraction/languages/test_python_strict.py failing on main. Each is a different kind of failure:

1. comprehensions: the added functional-builtin alternative `\b(?:map|filter|reduce|starmap)\(` matched the METHOD `qs.filter(`, because \b holds after a dot. That is exactly the false positive test_python_comprehensions_was_fixed_from_a_javascript_copy_paste guards (Django's `User.objects.filter(...)`). Now: bare `map(` / `filter(` / `reduce(` / `starmap(`, plus the explicit `functools.reduce(` and `itertools.starmap(` forms; a method of anything else no longer counts.
2. bitwise_ops: #9308 deliberately stopped counting an operator after the first quote on a line (its own comment states the cost). The old test still asserted the pre-change behaviour (`re.compile(r"^a~b<<")` matching). The test now documents the new rule: operator before the quote counts, inside a string literal does not. This narrows #2535 / #8866's "no string shielding" decision; flagged in the PR for the owner.

Re-blessed on main's pin (language-crucible v1.8.0): both golden-master legs (90 differences, all comprehension-count and cluster-distance shifts), the one family-baseline cell it moves (python/comprehensions: n_family 177 -> 175, recall 0.859 -> 0.848) and the family-validity SVGs. The full family sweep also reports 11 stale cells in c / go / javascript / rust / typescript that this change does not touch; they are left as they are.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@squid-protocol
squid-protocol marked this pull request as ready for review November 25, 2026 17:41
squid-protocol and others added 2 commits November 25, 2026 12:42
…ted files re-blessed in the next commit)

main moved (Swift keyword families, #9317) and re-blessed the same golden-master files, the family baseline and the family-validity charts. The conflicted generated files are main's version here only as a base; the next commit regenerates them on the merged tree.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ee merged with main (Swift keyword families)

6 differences per golden-master leg. family_oracle_sweep agrees with the merged baseline except for 11 cells (c, go, javascript, rust, typescript) that are stale on main and unrelated to this change; the python/comprehensions cell and the new Swift cells match.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…protocols #9315)

#9315 touched no engine files, so the golden masters are unchanged. The only conflict was tests/family_validity_baseline.json: main's file with this change's one cell (python/comprehensions: n_family 177 -> 175, recall 0.859 -> 0.848) re-applied, and the two family-validity SVGs regenerated from it (--check passes).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@squid-protocol
squid-protocol enabled auto-merge (squash) November 25, 2026 18:07
@squid-protocol
squid-protocol merged commit b637a43 into main Nov 25, 2026
73 checks passed
@squid-protocol
squid-protocol deleted the fix-python-strict-keyword-family-tests branch November 25, 2026 18:16
squid-protocol added a commit that referenced this pull request Nov 25, 2026
…ed in the next commit)

main took the python keyword-family fix (#9316), Swift keyword families, decoy protocols and others, which re-blessed the same golden masters, family baseline and charts. The 17 conflicted generated files are main's version here only as a base.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
squid-protocol added a commit that referenced this pull request Nov 25, 2026
… on the tree merged with main

Reran on the merge of origin/main (python keyword-family fix #9316, Swift keyword families, decoy protocols) with the v1.9.0 corpus and pin: both golden-master legs, family_oracle_sweep --write (every pinned cell carries 'language-crucible v1.9.0'; swept with the selfscan venv, which the committed baseline matches), the family-validity charts, the tri-comparison ledger and points doc. tree_sitter_accuracy_audit --all --ci (37 OK) and call_graph_accuracy --ci pass. Ledger vs main: 0 removed, 0 status changes, 51 new unvalidated. A read-only crucible_check passes both legs afterwards.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
squid-protocol added a commit that referenced this pull request Nov 25, 2026
…cible pin to v1.9.0 (#9307)

* test(crucible): rebless fixtures and baselines for the language-crucible v1.9.0 candidate (fd4fb0f)

Regenerates every artifact the BUMPING_THE_CRUCIBLE_PIN checklist names, against language-crucible
main fd4fb0f (v1.8.0 plus 12 commits: 53 new folders, 608 new files, no new categories). The pin
itself is NOT moved and no tag exists yet: tests/crucible_pins.toml still says v1.8.0, so this
branch is expected to be red in CI until the tag is cut and the pin is bumped on top of it.

- golden_master_audit + golden_master_zero_dep_audit (both legs, CI-matched venvs, under golden-lock)
- tri-comparison ledger + chart + points-of-interest (51 new entries, all unvalidated; 0 removed,
  0 status changes)
- tree-sitter accuracy history + chart; summary table in language_standards/__init__.py
- 13 stale tree-sitter baselines: apex csharp dart fortran haskell kotlin makefile matlab
  objective-c ruby scala solidity swift (exactly the languages whose corpus grew; the other 24 match)
- ctags_reader: decode ctags output with errors="replace". ctags can cut a field mid-character, which
  crashed tri_comparison_chart on the new Kotlin sources (UnicodeDecodeError 0xbb); + regression test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* chore(crucible): bump the language-crucible pin v1.8.0 -> v1.9.0

v1.9.0 is language-crucible fd4fb0f (the commit the fixtures in the previous commit were blessed
against): 53 new folders, 555 source files, no new categories.
https://github.com/squid-protocol/language-crucible/releases/tag/v1.9.0

tests/crucible_pins.toml is the only source of the pin; docs/self_scan/README.md's pin note and
clone command follow it. Generated reports that state the version they were measured at
(docs/*_family_contracts.md) and test fixture strings are left as they are.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(crucible-bump): decode ctags via source_text; rerun the family sweep and call-graph baseline for v1.9.0

CI on the first push of the bump found three things the BUMPING_THE_CRUCIBLE_PIN checklist does not list:

1. tests/test_source_reads.py (#3813) rejected the ctags fix: errors="replace" is a lossy handler.
   read_ctags_symbols now captures bytes and decodes through gitgalaxy.core.source_text.decode_bytes
   (no byte dropped or replaced). The regression test fails against main's original reader and passes
   with this one.
2. tests/tools/test_family_oracle_sweep.py: every pinned cell in tests/family_validity_baseline.json
   names the pin it was measured on. Reran `family_oracle_sweep.py --write` at v1.9.0 (the crucible
   checkout is exactly the tag). 178 cells take the new label; counts moved where corpora grew;
   11 cells changed status. Two runs, at different box loads, produced byte-identical files.
3. Call Graph Accuracy Audit has its own committed baseline (tests/call_graph_accuracy_baseline.json)
   that the larger apex / fortran / haskell / objective-c / ruby corpora regress. Regenerated with
   `call_graph_accuracy.py --regenerate` after reading the cause buckets; local numbers equal the ones
   CI printed (objective-c precision 97.8 -> 84.7: method-signature `void` and selector label parts such
   as `forKey` are taken as callees; ruby recall 96.3 -> 93.9: `raise` missed, Sorbet `void` taken as a call).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* ci: re-trigger checks after the GitHub incident dropped the push event for 3f15f01

No content change. The branch already held 3f15f01 but the PR never picked it up (Pull Requests / Actions / Webhooks were degraded), so no checks ran on it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test(crucible): re-bless fixtures and the family sweep for v1.9.0 on the tree merged with main

Reran, on the merge of origin/main (3 keyword-family commits) with the v1.9.0 corpus: both golden-master legs, family_oracle_sweep --write, the tri-comparison ledger + points doc. tree_sitter_accuracy_audit --all --ci and call_graph_accuracy --ci pass unchanged. Ledger vs main: 0 removed, 0 status changes, 51 new unvalidated.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* docs(crucible-bump): regenerate the family-validity SVGs from the v1.9.0 sweep

test_family_validity_chart::test_committed_svgs_are_current: both SVGs are rendered from tests/family_validity_baseline.json, which the v1.9.0 sweep rewrote. family_validity_chart.py --check passes.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test(crucible): re-bless fixtures, family sweep and charts for v1.9.0 on the tree merged with main

Reran on the merge of origin/main (python keyword-family fix #9316, Swift keyword families, decoy protocols) with the v1.9.0 corpus and pin: both golden-master legs, family_oracle_sweep --write (every pinned cell carries 'language-crucible v1.9.0'; swept with the selfscan venv, which the committed baseline matches), the family-validity charts, the tri-comparison ledger and points doc. tree_sitter_accuracy_audit --all --ci (37 OK) and call_graph_accuracy --ci pass. Ledger vs main: 0 removed, 0 status changes, 51 new unvalidated. A read-only crucible_check passes both legs afterwards.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
squid-shepherd Bot pushed a commit that referenced this pull request Nov 25, 2026
…(Part of #9321) (#9322)

Class guard for the #9308 regression fixed by #9316.

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.

1 participant