mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +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__()
|
||||
type_var_dict = {}
|
||||
if annotation_name == 'Iterable' and not is_class_value:
|
||||
given = self.get_generics()
|
||||
if given:
|
||||
return given[0].infer_type_vars(
|
||||
annotation_generics = self.get_generics()
|
||||
if annotation_generics:
|
||||
return annotation_generics[0].infer_type_vars(
|
||||
value_set.merge_types_of_iterate(),
|
||||
)
|
||||
|
||||
else:
|
||||
# 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
|
||||
|
||||
@@ -187,9 +187,10 @@ class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex):
|
||||
|
||||
annotation_name = self.py__name__()
|
||||
type_var_dict = {}
|
||||
annotation_generics = self.get_generics()
|
||||
|
||||
if annotation_name == 'Type':
|
||||
given = self.get_generics()
|
||||
if given:
|
||||
if annotation_generics:
|
||||
if is_class_value:
|
||||
for element in value_set:
|
||||
element_name = element.py__name__()
|
||||
@@ -200,20 +201,18 @@ class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex):
|
||||
)
|
||||
|
||||
else:
|
||||
return given[0].infer_type_vars(
|
||||
return annotation_generics[0].infer_type_vars(
|
||||
value_set,
|
||||
is_class_value=True,
|
||||
)
|
||||
|
||||
elif annotation_name == 'Callable':
|
||||
given = self.get_generics()
|
||||
if len(given) == 2:
|
||||
return given[1].infer_type_vars(
|
||||
if len(annotation_generics) == 2:
|
||||
return annotation_generics[1].infer_type_vars(
|
||||
value_set.execute_annotation(),
|
||||
)
|
||||
|
||||
elif annotation_name == 'Tuple':
|
||||
annotation_generics = self.get_generics()
|
||||
tuple_annotation, = self.execute_annotation()
|
||||
# TODO: is can we avoid using this private method?
|
||||
if tuple_annotation._is_homogenous():
|
||||
|
||||
Reference in New Issue
Block a user