mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Add handling of nested generic callables
Previously tests for these were passing somewhat by accident, however this commit's parent adds a case which showed that the handling was missing. Note that this also relies on the recent fix for nested tuples which changed the `isinstance` check in `define_generics`.
This commit is contained in:
@@ -217,9 +217,24 @@ class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex):
|
|||||||
|
|
||||||
elif annotation_name == 'Callable':
|
elif annotation_name == 'Callable':
|
||||||
if len(annotation_generics) == 2:
|
if len(annotation_generics) == 2:
|
||||||
return annotation_generics[1].infer_type_vars(
|
if is_class_value:
|
||||||
value_set.execute_annotation(),
|
# This only applies if we are comparing something like
|
||||||
)
|
# List[Callable[..., T]] with Iterable[Callable[..., T]].
|
||||||
|
# First, Jedi tries to match List/Iterable. After that we
|
||||||
|
# will land here, because is_class_value will be True at
|
||||||
|
# that point. Obviously we also compare below that both
|
||||||
|
# sides are `Callable`.
|
||||||
|
for element in value_set:
|
||||||
|
element_name = element.py__name__()
|
||||||
|
if element_name == 'Callable':
|
||||||
|
merge_type_var_dicts(
|
||||||
|
type_var_dict,
|
||||||
|
merge_pairwise_generics(self, element),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return annotation_generics[1].infer_type_vars(
|
||||||
|
value_set.execute_annotation(),
|
||||||
|
)
|
||||||
|
|
||||||
elif annotation_name == 'Tuple':
|
elif annotation_name == 'Tuple':
|
||||||
tuple_annotation, = self.execute_annotation()
|
tuple_annotation, = self.execute_annotation()
|
||||||
|
|||||||
@@ -206,40 +206,36 @@ for a in list_func_t_to_list_t(12):
|
|||||||
a
|
a
|
||||||
|
|
||||||
|
|
||||||
# The following are all actually wrong, however we're mainly testing here that
|
|
||||||
# we don't error when processing invalid values, rather than that we get the
|
|
||||||
# right output.
|
|
||||||
|
|
||||||
x0 = list_func_t_to_list_t(["abc"])[0]
|
x0 = list_func_t_to_list_t(["abc"])[0]
|
||||||
#? str()
|
#?
|
||||||
x0
|
x0
|
||||||
|
|
||||||
x2 = list_func_t_to_list_t([tpl])[0]
|
x2 = list_func_t_to_list_t([tpl])[0]
|
||||||
#? tuple()
|
#?
|
||||||
x2
|
x2
|
||||||
|
|
||||||
x3 = list_func_t_to_list_t([tpl_typed])[0]
|
x3 = list_func_t_to_list_t([tpl_typed])[0]
|
||||||
#? tuple()
|
#?
|
||||||
x3
|
x3
|
||||||
|
|
||||||
x4 = list_func_t_to_list_t([collection])[0]
|
x4 = list_func_t_to_list_t([collection])[0]
|
||||||
#? dict()
|
#?
|
||||||
x4
|
x4
|
||||||
|
|
||||||
x5 = list_func_t_to_list_t([collection_typed])[0]
|
x5 = list_func_t_to_list_t([collection_typed])[0]
|
||||||
#? dict()
|
#?
|
||||||
x5
|
x5
|
||||||
|
|
||||||
x6 = list_func_t_to_list_t([custom_generic])[0]
|
x6 = list_func_t_to_list_t([custom_generic])[0]
|
||||||
#? CustomGeneric()
|
#?
|
||||||
x6
|
x6
|
||||||
|
|
||||||
x7 = list_func_t_to_list_t([plain_instance])[0]
|
x7 = list_func_t_to_list_t([plain_instance])[0]
|
||||||
#? PlainClass()
|
#?
|
||||||
x7
|
x7
|
||||||
|
|
||||||
for a in list_func_t_to_list_t([12]):
|
for a in list_func_t_to_list_t([12]):
|
||||||
#? int()
|
#?
|
||||||
a
|
a
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user