jedi
jedi copied to clipboard
Jedi doesn't support PEP 604 (union types as `X | Y`)
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
This is fixed on master.
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.