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: Certain cases interpreted as subscript instead of generic_type #291

Closed
2 tasks done
JaagupAverin opened this issue Dec 7, 2024 · 1 comment · Fixed by #292
Closed
2 tasks done

bug: Certain cases interpreted as subscript instead of generic_type #291

JaagupAverin opened this issue Dec 7, 2024 · 1 comment · Fixed by #292
Labels

Comments

@JaagupAverin
Copy link

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

In certain cases where we deal with generics (such as user defined generic classes), the generics between square brackets get interpreted as a subscript as opposed to a generic.

Steps To Reproduce/Bad Parse Tree

  1. e.g in Tree-sitter playground:
x: list[int] = 0
y: type[int] = int
  1. list[int] is correctly classified as a generic_type
  2. type[int] is incorrectly classified as subscript

Alternatively for similar output:

class MyGeneric[T]:
	pass
    
MyAlias = MyGeneric[int]

Expected Behavior/Parse Tree

Both cases should be generic_types.

Repro

No response

@amaanq
Copy link
Member

amaanq commented Dec 22, 2024

The first case is definitely solvable, but the second case not so much, because it's truly ambiguous as to whether or not it's a subscript or a generic type. That would require semantic information about the code, which is typically something an interpreter/compiler/LSP does, and not tree-sitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants