jedi icon indicating copy to clipboard operation
jedi copied to clipboard

Jedi doesn't support PEP 604 (union types as `X | Y`)

Open GalaxySnail opened this issue 2 years ago • 2 comments

Jedi doesn't support PEP 604:

import jedi

code = """\
from typing import Union
data: Union[bytes, bytearray]
data.
"""

script = jedi.Script(code=code)
completions = script.complete(line=3, column=5)
print(completions)
assert completions[0].complete == "append"

code = """\
data: bytes | bytearray
data.
"""

script = jedi.Script(code=code)
completions = script.complete(line=2, column=5)
print(completions)
assert completions == []

python version: 3.10.2 jedi version: 0.18.1

GalaxySnail avatar Apr 13 '22 08:04 GalaxySnail

This is fixed on master.

davidhalter avatar Nov 11 '22 20:11 davidhalter

As mentioned in #1851, there are still some cases not supported:

type_in_string: int | "str"

#? int() str()
type_in_string


from typing import Union

pep604_with_typing_union: int | Union[str, list]

#? int() str() list()
pep604_with_typing_union


from typing import TypeVar
T = TypeVar("T")

def generic_func(arg: T) -> int | str | T:
    pass

#? int() str() bytes()
generic_func(b"hello")

So it may be better to let this issue open.

GalaxySnail avatar Nov 12 '22 08:11 GalaxySnail