Repository navigation
fix!: expose exception aliases as identifier fields - #38
Merged
Merged
Conversation
Keep exception values separate from their bound names and restrict expression as-patterns to with bindings. Update metadata and highlight handling for the direct handler fields. Co-authored-by: WillBooster (Codex CLI) <codex@willbooster.com>
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.
Why
except Error as caughtcurrently places both names inside anas_patternvalue instead of exposing the handler's alias field. This makes direct identifier-field queries impossible and also accepts non-identifier exception aliases. This addressestree-sitter/tree-sitter-python#311.Requirements
valueand identifier aliases throughaliasdirectly on the handler, because clients should not need a separate as-pattern traversal for a declared field.Customer Summary
Exception handlers expose their exception expression and alias as separate fields. Handler aliases must be identifiers. Existing with-item and match-pattern binding trees remain available.
Technical Summary
except_clause.aliasnow accepts identifier forms directly.with_itemexplicitly acceptsas_pattern, which is removed from the general expression supertype. The exception highlight query uses the resulting direct exception values, and generated node metadata and corpus expectations reflect those fields.Testing
All current-head PR CI checks pass.
The new public WASM/query regression fails on main: direct identifier alias queries cannot compile, and attribute aliases are accepted.
bun run verifypasses with no code-gauge findings in changed code.Canonical
CARGO_BUILD_JOBS=2 bun run build-wasmsucceeds using 210 corpus inputs and 12 tracked source files; six focused test files pass 14 tests, including all 210 corpus cases and existing match/with bindings, union queries, and type highlights.Native highlight rendering preserves constructor captures for uppercase exception types.
CPython3.9 accepts 20 ordinary-handler source forms and rejects 3 non-identifier alias forms. Starred handlers and Python3.14 multiple-exception syntax are checked against the official language reference and parser regressions.
Notes
This changes exception-handler ASTs: query
except_clausefields directly instead of looking for anas_pattern_targetunder its value. General expressions no longer acceptasbindings; with items keep their existing binding shape.