forked from VimPlug/jedi
Implement new-style unions with TypeVars
This commit is contained in:
@@ -31,6 +31,7 @@ from jedi.inference.context import CompForContext
|
|||||||
from jedi.inference.value.decorator import Decoratee
|
from jedi.inference.value.decorator import Decoratee
|
||||||
from jedi.plugins import plugin_manager
|
from jedi.plugins import plugin_manager
|
||||||
from jedi.inference.gradual.typing import ProxyTypingValue, IGNORE_ANNOTATION_PARTS
|
from jedi.inference.gradual.typing import ProxyTypingValue, IGNORE_ANNOTATION_PARTS
|
||||||
|
from jedi.inference.gradual.type_var import TypeVar
|
||||||
|
|
||||||
operator_to_magic_method = {
|
operator_to_magic_method = {
|
||||||
'+': '__add__',
|
'+': '__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)
|
result = (left_values or NO_VALUES) | (right_values or NO_VALUES)
|
||||||
return _literals_to_types(state, result)
|
return _literals_to_types(state, result)
|
||||||
elif operator_str == "|" and all(
|
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)
|
for value in itertools.chain(left_values, right_values)
|
||||||
):
|
):
|
||||||
# ^^^ A naive hack for PEP 604
|
# ^^^ A naive hack for PEP 604
|
||||||
|
|||||||
@@ -387,3 +387,11 @@ first(custom_partial2_unbound_instance)
|
|||||||
|
|
||||||
#? str()
|
#? str()
|
||||||
values(custom_partial2_unbound_instance)[0]
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user