Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Inconsistency when parsing | union operator #293

Open
2 tasks done
omriel1 opened this issue Dec 28, 2024 · 0 comments
Open
2 tasks done

bug: Inconsistency when parsing | union operator #293

omriel1 opened this issue Dec 28, 2024 · 0 comments
Labels

Comments

@omriel1
Copy link

omriel1 commented Dec 28, 2024

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
@omriel1 omriel1 added the bug label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant