Skip to content

fix!: expose exception aliases as identifier fields - #38

Merged
exKAZUu merged 1 commit into
mainfrom
fix/exception-alias-fields
Oct 20, 2026
Merged

exKAZUu merged 1 commit into
mainfrom
fix/exception-alias-fields

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Why

except Error as caught currently places both names inside an as_pattern value instead of exposing the handler's alias field. This makes direct identifier-field queries impossible and also accepts non-identifier exception aliases. This addresses tree-sitter/tree-sitter-python#311.

Requirements

  • required: Improve the forked grammar repositories as much as possible, ignoring backward compatibility; create a dedicated, nonduplicate PR from latest main for each actionable upstream item.
  • required: Run review-booster and complete-pr concurrently, then release the changes.
  • required: Make the redundant exception alias syntax work or remove it, as requested by the upstream issue.
  • required: Continue accepting ordinary and starred exception handlers, multiple exception types without aliases, and existing with-item and match-pattern bindings.
  • chosen: Expose exception types through value and identifier aliases through alias directly on the handler, because clients should not need a separate as-pattern traversal for a declared field.
  • chosen: Permit expression-style as-patterns only in with items, where they represent bindings, so they cannot consume the exception handler's alias or admit invalid aliases inside general expressions.

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.alias now accepts identifier forms directly. with_item explicitly accepts as_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 verify passes with no code-gauge findings in changed code.

  • Canonical CARGO_BUILD_JOBS=2 bun run build-wasm succeeds 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_clause fields directly instead of looking for an as_pattern_target under its value. General expressions no longer accept as bindings; with items keep their existing binding shape.

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>
@exKAZUu exKAZUu self-assigned this Oct 20, 2026
@exKAZUu
exKAZUu merged commit 27d78ed into main Oct 20, 2026
10 checks passed
@exKAZUu
exKAZUu deleted the fix/exception-alias-fields branch October 20, 2026 22:48
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