Skip to content

bug: Inconsistency when parsing | union operator #293

Open
@omriel1

Description

@omriel1

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-python

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

When using the | union operator, the output structure depends on the order of the types. For example:

def example(
    a: str | list[float] | bool,
    b: list[float] | str | bool,
):
	pass
  1. The types of a are parsed to recursive binary_operators, each with "right" and "left" nodes and list[float] is parsed to value and subscript
  2. types of b are parsed to union type, where list[float] is parsed as generic_type and str | bool to binary_operator.

Steps To Reproduce/Bad Parse Tree

Use the example above in the tree-sitter playground for python - https://tree-sitter.github.io/tree-sitter/7-playground.html

Expected Behavior/Parse Tree

I'd expect to get a consistent parsing, for example a recursive binary_operator or union.
Regarding the the subscript versus generic_type I believe it's similar to previous issue - #291 so I guess it's not solvable.

Repro

def example(
    a: str | list[float] | bool,
    b: list[float] | str | bool,
):
	pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions