mirror of
https://github.com/davidhalter/jedi.git
synced 2026-11-24 13:28:06 +08:00
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:
1 parent
5d273f4630
commit
96132587b7
1 file changed
+11
-11
@@ -445,17 +445,6 @@ def _infer_type_vars(annotation_value, value_set, is_class_value=False):
|
||||
)
|
||||
)
|
||||
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()
|
||||
tuple_annotation, = annotation_value.execute_annotation()
|
||||
# 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
|
||||
# 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()
|
||||
merge_pairwise_generics(annotation_generics, actual_generics)
|
||||
|
||||
|
||||
Reference in new issue
Block a user