Skip to content

fix(python): stop io/test rules double-counting globals/safety keywords (#2593) - #2626

Merged
squid-protocol merged 1 commit into
mainfrom
fix/2593-python-io-test-overlap
Sep 1, 2026
Merged

fix(python): stop io/test rules double-counting globals/safety keywords (#2593)#2626
squid-protocol merged 1 commit into
mainfrom
fix/2593-python-io-test-overlap

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • io: negative-lookahead os\.(?!environ\b)/sys\.(?!argv\b|path\b) so os.environ/sys.argv/sys.path (owned by globals) no longer double-count as io. Real os./sys. I/O calls (os.path, os.remove, sys.stdin, ...) still match.
  • test: dropped \bassert\b (already owned by safety) — a bare assert in production code is a validation signal, not a testing-framework signal. unittest/pytest/TestCase/fixture/patch/def test_/Mock are untouched.

Found while sweeping python's rosetta cross-language-consistency issue (#2593, epic #2560), classified via the rosetta-language-sweep skill's bucket taxonomy as real keyword-overlap bugs (not intended morphology) — both were already documented, unowned findings in keyword-rosetta's deviation_ledger.json (os-sys-prefix-overlaps-io, assert-overlaps-safety-and-test).

Measured effect

keyword-rosetta data/python/a.py: io 3→1, test 3→2 — both now match planted intent exactly (tools/verify_language.py python: PASS, 80 assertions). Live cross-language deviation count for python: 5 red / 3 amber → 4 red / 3 amber (tools/language_deviations.py python). safety/state_mutation/doc/comment_lines are untouched — classified as median-inflation-elsewhere or out of scope for this PR (see #2593 update comment).

While triaging this, also found and filed a separate cross-cutting issue (#2625, not fixed here): comment_lines conflates blank lines with real documentation lines engine-wide (total_loc includes blanks, coding_loc doesn't) — python's corpus files just have an unusually high blank-line ratio, which is why it surfaces loudest there.

Also adds the keyword-rosetta capstone section (§11) to docs/language_status/python.md.

Cross-repo

  • Companion corpus PR: keyword-rosetta#13, ENGINE_REF pinned to pull/2626/head.
  • rosetta-audit on this PR fails, and that's expected — it checks out keyword-rosetta at the pinned KEYWORD_ROSETTA_REF (still main, i.e. the pre-fix manifest) against this PR's engine build, so it correctly catches the io/test drift at the source (a.py: io expected 3, got 1, a.py: test expected 3, got 2). Resolves once keyword-rosetta#13 merges and this PR bumps KEYWORD_ROSETTA_REF to that commit, per docs/ecosystem.md's rosetta-sweep choreography. Do not merge this PR until then.

Test plan

  • pytest tests/extraction/languages/test_python_strict.py tests/extraction/languages/test_python.py — 176 passed, new regression tests added (test_python_io_excludes_globals_overlap, test_python_test_excludes_bare_assert, plus 5 new parametrized cases)
  • Full suite: pytest tests/ — 7169 passed
  • ruff_audit.py --ci / mypy_audit.py --ci — no new findings
  • crucible_check.py — PASS on both full_precision and zero_dependency after re-blessing (321 diffs, all test/io signal drops in python-classified files + downstream risk-percentage reflows — reviewed, expected shape, nothing outside python)
  • tri_comparison_chart.py --all --ci — no func/class precision regression
  • keyword-rosetta tools/verify_language.py python — PASS
  • CI green except rosetta-audit (expected per above)

🤖 Generated with Claude Code

…ds (#2593)

Two keyword-overlap bugs found while sweeping python's rosetta cross-language
consistency deviations (#2593, epic #2560):

- `io`'s `os\.`/`sys\.` matched ANY os./sys. attribute access, overlapping
  `globals`' own `os.environ`/`sys.argv`/`sys.path` -- a planted globals read
  was double-counted as io too. Negative lookaheads now carve out exactly
  those three tokens; os.path/os.remove/sys.stdin/etc. still count as io.
- `test` included bare `\bassert\b`, already owned by `safety` -- a runtime
  invariant check in production code (no test framework involved) was
  miscounted as a testing signal. Removed; unittest/pytest/TestCase/fixture/
  patch/def test_/Mock already cover real testing idioms without it.

keyword-rosetta corpus measured: a.py io 3->1, test 3->2 (now matches planted
intent exactly). Live deviation count: 5 red / 3 amber -> 4 red / 3 amber.
Ledger entries os-sys-prefix-overlaps-io (resolved for python) and
assert-overlaps-safety-and-test (python removed, still reproduces for c/perl)
updated in keyword-rosetta#TBD.

Golden masters re-blessed (test/io signal drift in python-classified files
across the crucible corpus + downstream risk-percentage reflows, expected
shape). tri-comparison --ci: no func/class precision regression.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 5700d9f into main Sep 1, 2026
30 of 31 checks passed
@squid-protocol
squid-protocol deleted the fix/2593-python-io-test-overlap branch September 1, 2026 01:32
squid-protocol added a commit to squid-protocol/keyword-rosetta that referenced this pull request Sep 1, 2026
Engine PR squid-protocol/gitgalaxy#2626 removes two keyword-overlap bugs in
python's io/test rules (os./sys. no longer double-counts globals'
os.environ/sys.argv; assert no longer double-counts safety). Re-baselining
here per the rosetta-language-sweep skill's Phase 3-5:

- data/python/expected_signals.json: a.py io 3->1, test 3->2, notes updated
  to point at the engine fix instead of baking in the old cross-contamination
- deviation_ledger.json: os-sys-prefix-overlaps-io resolved for python
  (still_reproduces: false, languages_seen now empty); assert-overlaps-
  safety-and-test has python removed from languages_seen (still reproduces
  for c/perl, their own rule files untouched)
- ENGINE_REF pinned to pull/2626/head until the engine PR merges
- docs/bias_data.json, bias_report.md, bias_variance_chart.svg,
  findings_by_language.md regenerated via tools/bias_report.py -- only
  python's cells moved (io 6->4, keyword_hits 244->241); every other
  language's numbers are byte-identical to before

Verified: tools/verify_language.py python -- PASS, 80 assertions.
python: 5 red / 3 amber -> 4 red / 3 amber (tools/language_deviations.py).

Cross-repo: companion engine PR squid-protocol/gitgalaxy#2626. Reset
ENGINE_REF to main and merge this PR only after #2626 is approved, per
docs/ecosystem.md's rosetta-sweep choreography (gitgalaxy PR merges last,
bumping KEYWORD_ROSETTA_REF to this repo's post-merge commit).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
squid-protocol added a commit that referenced this pull request Sep 1, 2026
…sweep) (#2630)

Third rosetta capstone after jcl.md/cobol.md §10 (numbered §11 here — this
doc already uses §10 for its tri-comparison section). Records the #2593
sweep: #2626's io/test overlap fixes, the bucket-5 residuals pinned to
#2546/#2535/#2625, and why the issue stays open.


Claude-Session: https://claude.ai/code/session_01BsVATdyMPhUoAUNBKbMUVi

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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