forked from VimPlug/jedi
Implement unions with forward references
This commit is contained in:
@@ -37,12 +37,15 @@ def infer_annotation(context, annotation):
|
|||||||
"Inferred typing index %s should lead to 1 object, not %s" % (annotation, value_set))
|
"Inferred typing index %s should lead to 1 object, not %s" % (annotation, value_set))
|
||||||
return value_set
|
return value_set
|
||||||
|
|
||||||
inferred_value = list(value_set)[0]
|
strings_removed = NO_VALUES
|
||||||
if is_string(inferred_value):
|
for part in value_set:
|
||||||
result = _get_forward_reference_node(context, inferred_value.get_safe_value())
|
if is_string(part):
|
||||||
if result is not None:
|
result = _get_forward_reference_node(context, part.get_safe_value())
|
||||||
return context.infer_node(result)
|
if result is not None:
|
||||||
return value_set
|
strings_removed |= context.infer_node(result)
|
||||||
|
continue
|
||||||
|
strings_removed |= ValueSet([part])
|
||||||
|
return strings_removed
|
||||||
|
|
||||||
|
|
||||||
def _infer_annotation_string(context, string, index=None):
|
def _infer_annotation_string(context, string, index=None):
|
||||||
|
|||||||
@@ -230,3 +230,11 @@ def use_type_with_annotation() -> type[int]: ...
|
|||||||
|
|
||||||
#? int
|
#? int
|
||||||
use_type_with_annotation()
|
use_type_with_annotation()
|
||||||
|
|
||||||
|
def union_with_forward_references(x: int | "str", y: "int" | str, z: "int | str"):
|
||||||
|
#? int() str()
|
||||||
|
x
|
||||||
|
#? int() str()
|
||||||
|
y
|
||||||
|
#? int() str()
|
||||||
|
z
|
||||||
|
|||||||
Reference in New Issue
Block a user