Repository navigation
fix(python): vectorized_math ignores '@' in strings and comments (#4136) - #4148
Merged
Merged
Conversation
The code stream keeps string literals, so python's matmul '@' arm counted "text-embedding-gecko@003", "[email protected]" fixtures and b"[email protected]". Add a language-agnostic `outside_literals` scope filter that drops any match touching a string literal or comment in the existing index-aligned shield (_build_indentation_safe_stream), and opt python vectorized_math into it. Also count the augmented `a @= b` form, which the operand lookahead rejected. Golden masters: 9 python files lose string-literal hits (fastapi test_response_model_data_filter*.py 7 -> 0 each, plus twisted, numpy, cython, other fastapi tests); nothing else moves. Co-Authored-By: Claude Opus 5.5 (1M context) <[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.
Fixes #4136
What changed
outside_literals(detector.py_apply_scope_filter). It uses the existing_scope_filtersmechanism (CRITICAL ENGINE RULE 17), so it only ever removes matches and counts, spatial maps and threat locations stay consistent. A match is kept only if its span is identical in the index-aligned string/comment shield that_build_indentation_safe_streamalready builds for the indentation slicer. If any character of the match sits in a string literal or comment, the match is dropped. Nothing new was written for the masking itself.vectorized_mathnow declares"_scope_filters": {"vectorized_math": "outside_literals"}. The@arm also accepts the augmented forma @= b. Before, the=failed the operand lookahead, so@=was never counted.@app.get(...), an indented@property, and a decorator right after a)line).signal_contracts.py, re-rendereddocs/signal_contracts.md), rule 18 inhow_to_add_a_language.md, and thevectorized_mathschema line now name the opt-in filter.Known limitation: a matmul inside an f-string interpolation (
f"{a @ b}") is masked along with the rest of the string.Differential scan / golden masters
crucible_check.py(both modes) showed 9 differences per fixture. All of them are invectorized_math, and nothing else moved. Re-blessed with--update --yes:"[email protected]"string fixtures"[email protected]"b"[email protected]""... every @cname method ..."string'einsum.cpp'path stringadd_newdocstringsmatmul(/tensordot/.dot(calls stayI checked every dropped match against the source line. All of them are string or comment text, and none is a real operator.
Verification
tests/extraction/languages/test_python_strict.py: 109 passed, including the new vectorized_math fires on '@' inside Python string literals #4136 tests (strings, comments, docstrings, decorators,a @ b,f(a)@g(b),a @= b, a mixed line, and ReDoS on the new arm).-n 8): 13353 passed. 3 ReDoS timing tests failed under load while the crucible scan was running in parallel (css, javascript import, zig). None touch Python, and all 3 pass when re-run serially.tests/tools/audit_check.py: ruff, mypy, dead-key and ast-accuracy all clear.signal_contract_audit.py --ci: no new findings.🤖 Generated with Claude Code