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

Jedi does not recognise type parameter lists. #2025

Open
haiksgit opened this issue Sep 17, 2024 · 2 comments
Open

Jedi does not recognise type parameter lists. #2025

haiksgit opened this issue Sep 17, 2024 · 2 comments

Comments

@haiksgit
Copy link

The Issue

Starting from Python 3.12, functions, classes and type aliases may contain a type parameter list. However, this new syntax is not supported by Jedi. For example:

import jedi

source = '''
def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

def concat[A, B](a: list[A], b: list[B]) -> list[A | B]:
    """Concatenate two lists."""
    return a + b
'''

script = jedi.Script(source)

add = script.infer(2, 7)
concat = script.infer(6, 10)

print(add)     #-> [<Name full_name='__main__.add', description='def add'>]
print(concat)  #-> []

Because of this, language servers that use Jedi (such as jedi-language-server or python-lsp-server) cannot provide hover information for objects with type parameter lists.

Version Information

  • Python 3.12.6
  • Jedi 0.19.1
@PeterJCLaw
Copy link
Collaborator

My guess is that this is a parso issue (looking their reveals davidhalter/parso#221), though Jedi may need subsequent changes to make use of the parameters.

@davidhalter
Copy link
Owner

@PeterJCLaw is correct. I wanted to change this in parso a while ago, which would have taken maybe an hour, but the problem is that this is absolutely non-trivial in Jedi and even simply ignoring it in Jedi is probably quite a bit of work.

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

No branches or pull requests

3 participants