fix(parser): refine Python parser depth accounting#7813
Conversation
Coverage Results ✅ |
|
@copilot can you compare and contrast this with how depth accounting is handled in rust? |
Hi @alanmcruickshank , let me try to contrast it In Python, the PR changes Rust is different in two important ways. First, it enforces max depth from the explicit frame stack inside the iterative parser, not from a shared context-manager counter: see So the practical contrast is this: old Python overcounted because every wrapper scope incremented one shared depth counter; this PR fixes that selectively. Rust already avoids that exact problem because depth is tied to active parse frames, not logging or dispatch scopes. But Rust is not identical to the post-PR Python behavior either, because some helper work is isolated into separate subparses, which means Rust can undercount relative to a fully cumulative notion of nested helper activity. I would not expect the exact false-positive fixed by this PR to reproduce in Rust. The Rust side already passes the same configured limit through from Does that help? |
Brief summary of the change made
Fix a false positive
max_parse_depthfailure in the Python parser by excluding helper-only match wrappers from depth accounting.Fixes #7805
What changed
track_parse_depthtoParseContext.deeper_match()Ref,Sequence,AnyNumberOf,Delimited, and greedy terminator matchingNote: Python parser only. Rust parser unchanged.
Are there any other side effects of this change that we should be aware of?
Pull Request checklist
Please confirm you have completed any of the necessary steps below.
Included test cases to demonstrate any code changes, which may be one or more of the following:
.ymlrule test cases intest/fixtures/rules/std_rule_cases..sql/.ymlparser test cases intest/fixtures/dialects(note YML files can be auto generated withtox -e generate-fixture-yml).test/fixtures/linter/autofix.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.
Summary by cubic
Fixes false positive
max_parse_deptherrors in the Python parser by not counting helper-only match wrappers toward depth. Prevents unexpected depth-limit failures (e.g., in T‑SQL). Rust parser remains unchanged.track_parse_depthtoParseContext.deeper_match()to control depth accounting.Written for commit 0b67b7d. Summary will update on new commits.