mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-06 22:33:59 +08:00
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))
|
||||
return value_set
|
||||
|
||||
inferred_value = list(value_set)[0]
|
||||
if is_string(inferred_value):
|
||||
result = _get_forward_reference_node(context, inferred_value.get_safe_value())
|
||||
if result is not None:
|
||||
return context.infer_node(result)
|
||||
return value_set
|
||||
strings_removed = NO_VALUES
|
||||
for part in value_set:
|
||||
if is_string(part):
|
||||
result = _get_forward_reference_node(context, part.get_safe_value())
|
||||
if result is not None:
|
||||
strings_removed |= context.infer_node(result)
|
||||
continue
|
||||
strings_removed |= ValueSet([part])
|
||||
return strings_removed
|
||||
|
||||
|
||||
def _infer_annotation_string(context, string, index=None):
|
||||
|
||||
@@ -230,3 +230,11 @@ def use_type_with_annotation() -> type[int]: ...
|
||||
|
||||
#? int
|
||||
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