Repository navigation
fix!: parse annotation unions consistently as types - #37
Merged
Merged
Conversation
Co-authored-by: WillBooster (Codex CLI) <codex@willbooster.com>
Co-authored-by: WillBooster (Codex CLI) <codex@willbooster.com>
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
The same union annotation produces different syntax trees depending on operand order.
str | intis a binary expression, whileIO[bytes] | int | List[int]mixes a union with a binary expression and a subscript. This is the ambiguity reported intree-sitter/tree-sitter-python#293,tree-sitter/tree-sitter-python#333, andtree-sitter/tree-sitter-python#334.Requirements
Customer Summary
Ordinary parameter, return, variable and type-alias annotations consistently expose named, qualified and generic union operands as types. Generic receivers retain their type nodes through member access and repeated type arguments. Qualified annotation names and constrained tuple elements also receive contextual type nodes. Value expressions and default argument values keep their existing expression representation.
Technical Summary
Route
typethrough the contextual expression grammar already used for type-parameter defaults. Its member and generic receivers accept nested generic types, supporting chains such asOuter[int].Inner[str].Leafanda[b][c] | d. Remove the duplicate generic, union and member rules and their stale conflicts. Constrained expressions retain their outer type wrapper in declaration and generic-argument contexts. Regenerate the parser and update the three affected corpus expectations.The union nodes remain recursive, preserving operand grouping. Arbitrary annotation expressions retain the general expression fallback.
Testing
str | int; its value-expression control passes. The generic-receiver regression reproduces the missing type nodes before the repair.ast.parse.bun run build-wasmpasses after integration with current main.bun run verifypasses. The existing code-gauge violations concern imported fixtures and scanner logic unchanged by this PR.Notes
This intentionally changes annotation AST shapes, so the title requests a major release. The runtime dependency and ABI remain unchanged.
Existing code-gauge errors remain in the unchanged scanner function
tree_sitter_python_external_scanner_scan;GrammarTests.testFuncdefinexamples/python2-grammar-crlf.py,examples/python2-grammar.py,examples/python3-grammar-crlf.py, andexamples/python3-grammar.py; and file NCSS plusGrammarTests.test_funcdefinexamples/python3.8_grammar.py. The imported parser fixtures stay intact, and changing the unrelated scanner would broaden this annotation change.