mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Extract common get_generics() calls
These no longer need to be guarded by the conditions now that we know these types are generic anyway.
This commit is contained in:
@@ -207,11 +207,12 @@ class GenericClass(ClassMixin, DefineGenericBase):
|
|||||||
annotation_name = self.py__name__()
|
annotation_name = self.py__name__()
|
||||||
type_var_dict = {}
|
type_var_dict = {}
|
||||||
if annotation_name == 'Iterable' and not is_class_value:
|
if annotation_name == 'Iterable' and not is_class_value:
|
||||||
given = self.get_generics()
|
annotation_generics = self.get_generics()
|
||||||
if given:
|
if annotation_generics:
|
||||||
return given[0].infer_type_vars(
|
return annotation_generics[0].infer_type_vars(
|
||||||
value_set.merge_types_of_iterate(),
|
value_set.merge_types_of_iterate(),
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Note: we need to handle the MRO _in order_, so we need to extract
|
# Note: we need to handle the MRO _in order_, so we need to extract
|
||||||
# the elements from the set first, then handle them, even if we put
|
# the elements from the set first, then handle them, even if we put
|
||||||
|
|||||||
@@ -187,9 +187,10 @@ class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex):
|
|||||||
|
|
||||||
annotation_name = self.py__name__()
|
annotation_name = self.py__name__()
|
||||||
type_var_dict = {}
|
type_var_dict = {}
|
||||||
|
annotation_generics = self.get_generics()
|
||||||
|
|
||||||
if annotation_name == 'Type':
|
if annotation_name == 'Type':
|
||||||
given = self.get_generics()
|
if annotation_generics:
|
||||||
if given:
|
|
||||||
if is_class_value:
|
if is_class_value:
|
||||||
for element in value_set:
|
for element in value_set:
|
||||||
element_name = element.py__name__()
|
element_name = element.py__name__()
|
||||||
@@ -200,20 +201,18 @@ class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return given[0].infer_type_vars(
|
return annotation_generics[0].infer_type_vars(
|
||||||
value_set,
|
value_set,
|
||||||
is_class_value=True,
|
is_class_value=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif annotation_name == 'Callable':
|
elif annotation_name == 'Callable':
|
||||||
given = self.get_generics()
|
if len(annotation_generics) == 2:
|
||||||
if len(given) == 2:
|
return annotation_generics[1].infer_type_vars(
|
||||||
return given[1].infer_type_vars(
|
|
||||||
value_set.execute_annotation(),
|
value_set.execute_annotation(),
|
||||||
)
|
)
|
||||||
|
|
||||||
elif annotation_name == 'Tuple':
|
elif annotation_name == 'Tuple':
|
||||||
annotation_generics = self.get_generics()
|
|
||||||
tuple_annotation, = self.execute_annotation()
|
tuple_annotation, = self.execute_annotation()
|
||||||
# TODO: is can we avoid using this private method?
|
# TODO: is can we avoid using this private method?
|
||||||
if tuple_annotation._is_homogenous():
|
if tuple_annotation._is_homogenous():
|
||||||
|
|||||||
Reference in New Issue
Block a user