forked from VimPlug/jedi
Clarify generic tuple inference
This hoist a loop invariant conditional check outside the loop making it clearer and one branch more obviously similar to the general type handling.
This commit is contained in:
@@ -445,17 +445,6 @@ def _infer_type_vars(annotation_value, value_set, is_class_value=False):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif annotation_name == 'Tuple':
|
elif annotation_name == 'Tuple':
|
||||||
# TODO: this logic is pretty similar to the general logic below, can
|
|
||||||
# we combine them?
|
|
||||||
|
|
||||||
for element in value_set:
|
|
||||||
py_class = element.get_annotated_class_object()
|
|
||||||
if not isinstance(py_class, GenericClass):
|
|
||||||
py_class = element
|
|
||||||
|
|
||||||
if not isinstance(py_class, DefineGenericBase):
|
|
||||||
continue
|
|
||||||
|
|
||||||
annotation_generics = annotation_value.get_generics()
|
annotation_generics = annotation_value.get_generics()
|
||||||
tuple_annotation, = annotation_value.execute_annotation()
|
tuple_annotation, = annotation_value.execute_annotation()
|
||||||
# TODO: is can we avoid using this private method?
|
# TODO: is can we avoid using this private method?
|
||||||
@@ -477,6 +466,17 @@ def _infer_type_vars(annotation_value, value_set, is_class_value=False):
|
|||||||
# treat the incoming values as needing to match the annotation
|
# treat the incoming values as needing to match the annotation
|
||||||
# exactly, just as we would for non-tuple annotations.
|
# exactly, just as we would for non-tuple annotations.
|
||||||
|
|
||||||
|
# TODO: this logic is pretty similar to the general logic below, can
|
||||||
|
# we combine them?
|
||||||
|
|
||||||
|
for element in value_set:
|
||||||
|
py_class = element.get_annotated_class_object()
|
||||||
|
if not isinstance(py_class, GenericClass):
|
||||||
|
py_class = element
|
||||||
|
|
||||||
|
if not isinstance(py_class, DefineGenericBase):
|
||||||
|
continue
|
||||||
|
|
||||||
actual_generics = py_class.get_generics()
|
actual_generics = py_class.get_generics()
|
||||||
merge_pairwise_generics(annotation_generics, actual_generics)
|
merge_pairwise_generics(annotation_generics, actual_generics)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user