Repository navigation
fix(core): close #1198's residual python function-extraction gap - #1205
Merged
Merged
Conversation
Two independent bugs in prism.py's Python docstring/comment stripping (the stage upstream of detector.py's function-boundary scanner) that both desync code_stream's line numbers from the real file, silently dropping a contiguous range of real `def`s from extraction: 1. _strip_python_docstrings replaced every matched docstring with a fixed single "\n" regardless of how many lines it actually spanned -- only line-count-neutral by coincidence for a 2-line docstring; every other length shifted every following line number by (2 - N) lines. This alone produced detector.py's own reported "dead zone" (_partition_segments..._apply_literal_shield, 7 functions). 2. The same function's triple-quote regex ran directly against raw text with no string-literal shielding, so a `'"""'`/`"'''"`-shaped sequence inside an ordinary (non-triple) string literal could false-open a "docstring" that only closed at the next real `"""` many lines later, swallowing every real line -- including further `def`s -- in between. Same bug class as #1184's fix to _apply_literal_shield, just never applied to this sibling implementation in prism.py. Fixed both by mirroring _apply_literal_shield's established pattern: preserve exactly as many newlines as the match spans, and fold plain string/comment recognition into the same atomic alternation so whichever construct starts first at a given position always wins (single-pass, no separate contraction-apostrophe or false-triple-quote hazard). A third, separate bug fully explains the issue's other reported gap (near-total extraction loss in test_rust_strict.py/test_objectivec_strict.py, both dense with embedded-language string fixtures): the `asm!`/`__asm__` entry in HANDSHAKE_REGISTRY (language_standards.py) was still unanchored -- the exact drift #1183/#1190 already fixed for <script>/<style>, just never applied to this third registry entry. A bare `asm!(` substring inside an ordinary Python string (e.g. a Rust safety_bypasses test fixture literally containing 'asm!("nop")') falsely triggered the embedded-language handshake and misrouted the rest of the file to assembly's rules. Anchored it to line-start like its two siblings. Verified corpus-wide against `ast` ground truth across all 228+ .py files in this repo (same methodology as docs/language_status/python.md §9): function recall 2333/2379 (98.1%) -> 2379/2379 (100%), 0 hallucinations, both before and after. tests/ast_accuracy_baseline.json, golden_master_ audit.json, and golden_master_zero_dep_audit.json regenerated via their sanctioned tools (ast_accuracy_audit.py --regenerate, update_golden_master.py) to bless this intentional, verified accuracy improvement -- diffs are total_loc/function-count increases on affected files plus expected downstream PageRank/3D-coordinate ripple. Full pytest suite (6787 passed), tests/tools/audit_check.py, and tests/tools/crucible_check.py (both modes) all clean. Fixes #1198. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
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.
Summary
Two independent bugs in
prism.py's Python docstring/comment stripping (upstream ofdetector.py's function-boundary scanner), plus a third in theasm!embedded-language handshake trigger, together account for all of #1198's reported gap:_strip_python_docstrings's newline-count bug — it replaced every matched docstring with a fixed single"\n"regardless of how many lines it actually spanned (line-count-neutral only by coincidence for a 2-line docstring). Every other length desynced every following line number by(2 - N)lines, accumulating across a file. This alone reproduceddetector.py's reported "dead zone" (_partition_segmentsthrough_apply_literal_shield, 7 functions in a row)._strip_python_docstrings's missing string-shielding — its triple-quote regex ran directly against raw text, so a'"""'/"'''"-shaped sequence inside an ordinary string literal (e.g.nxt.endswith('"""')) could false-open a "docstring" that only closed at the next real"""many lines later, swallowing every real line — including furtherdefs — in between. Same bug class as Contiguous 'dead zones' of real functions silently lost from extraction on production files, independent of mid-file language drift #1184's fix to_apply_literal_shield, just never applied to this sibling implementation.Fixed both by mirroring
_apply_literal_shield's established pattern: preserve exactly as many newlines as the match spans, and fold plain string/comment recognition into the same atomic alternation so whichever construct starts first at a given position always wins.Unanchored
asm!/__asm__handshake trigger (language_standards.py) — the same drift Mid-file language-switching (_partition_segments) can be permanently misled by a string literal that merely contains embedded-language delimiter text #1183/fix(core): stop detector.py's embedded-language handshake from firing inside string literals #1190 already fixed for<script>/<style>, just never applied to this thirdHANDSHAKE_REGISTRYentry. A bareasm!(substring inside an ordinary Python string (e.g. a Rustsafety_bypassestest fixture literally containing'asm!("nop")') falsely triggered the embedded-language handshake and misrouted the rest of the file to assembly's rules — this fully explains the issue's reported near-total extraction loss intest_rust_strict.py/test_objectivec_strict.py. Anchored it to line-start like its two siblings.Verification
Corpus-wide against
astground truth across all 228+.pyfiles in this repo (same methodology asdocs/language_status/python.md§9): function recall 2333/2379 (98.1%) → 2379/2379 (100%), 0 hallucinations both before and after.tests/ast_accuracy_baseline.json,tests/golden_master_audit.json,tests/golden_master_zero_dep_audit.jsonregenerated via their sanctioned tools (ast_accuracy_audit.py --regenerate,update_golden_master.py) to bless this intentional, verified accuracy improvement — diffs are total_loc/function-count increases on affected files plus the expected downstream PageRank/3D-coordinate ripple.pytest tests/: 6787 passed, 0 failed.tests/tools/audit_check.py: all clear (ruff/mypy/dead-key/ast-accuracy).tests/tools/crucible_check.py: both full-precision and zero-dependency modes PASS.Test plan
python tests/tools/audit_check.pypython tests/tools/crucible_check.pypython -m pytest tests/(full suite)python tests/ast_accuracy_audit.py(100% recall confirmed, no regressions)Fixes #1198.
🤖 Generated with Claude Code