diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 071fb8d4..ff5b4fc8 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -31,6 +31,7 @@ from jedi.inference.context import CompForContext from jedi.inference.value.decorator import Decoratee from jedi.plugins import plugin_manager from jedi.inference.gradual.typing import ProxyTypingValue, IGNORE_ANNOTATION_PARTS +from jedi.inference.gradual.type_var import TypeVar operator_to_magic_method = { '+': '__add__', @@ -530,7 +531,7 @@ def _infer_comparison(context, left_values, operator, right_values): result = (left_values or NO_VALUES) | (right_values or NO_VALUES) return _literals_to_types(state, result) elif operator_str == "|" and all( - value.is_class() or value.is_compiled() + value.is_class() or value.is_compiled() or isinstance(value, TypeVar) for value in itertools.chain(left_values, right_values) ): # ^^^ A naive hack for PEP 604 diff --git a/test/completion/pep0484_generic_parameters.py b/test/completion/pep0484_generic_parameters.py index c5230d13..50fdeba1 100644 --- a/test/completion/pep0484_generic_parameters.py +++ b/test/completion/pep0484_generic_parameters.py @@ -387,3 +387,11 @@ first(custom_partial2_unbound_instance) #? str() values(custom_partial2_unbound_instance)[0] + +def generic_func1(arg: T) -> int | str | T: pass +def generic_func2(arg: T) -> Union[int, str, T]: pass + +#? int() str() bytes() +generic_func1(b"hello") +#? int() str() bytes() +generic_func2(b"hello")