mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix inferring dict.values()
This commit is contained in:
@@ -300,6 +300,17 @@ class ContextSet(BaseContextSet):
|
||||
def get_item(self, *args, **kwargs):
|
||||
return ContextSet.from_sets(_getitem(c, *args, **kwargs) for c in self._set)
|
||||
|
||||
def try_merge(self, function_name):
|
||||
context_set = self.__class__()
|
||||
for c in self._set:
|
||||
try:
|
||||
method = getattr(c, function_name)
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
context_set |= method()
|
||||
return context_set
|
||||
|
||||
|
||||
NO_CONTEXTS = ContextSet()
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, AbstractFunction)):
|
||||
|
||||
def py__call__(self, arguments, need_param_match=False):
|
||||
function_execution = self.get_function_execution(arguments)
|
||||
if need_param_match and function_execution.matches_signature():
|
||||
if need_param_match and not function_execution.matches_signature():
|
||||
return NO_CONTEXTS
|
||||
return function_execution.infer()
|
||||
|
||||
|
||||
@@ -274,7 +274,6 @@ class TreeInstance(AbstractInstanceContext):
|
||||
# First check if the signature even matches, if not we don't
|
||||
# need to infer anything.
|
||||
continue
|
||||
print(bound)
|
||||
context_set = define_type_vars_for_execution(
|
||||
ContextSet(self.class_context),
|
||||
execution,
|
||||
|
||||
@@ -406,7 +406,7 @@ class TypeVar(_BaseTypingContext):
|
||||
return ContextSet.from_sets(
|
||||
l.infer() for l in self._constraints_lazy_contexts
|
||||
)
|
||||
debug.warning('Tried to infer a TypeVar without a given type')
|
||||
debug.warning('Tried to infer the TypeVar %r without a given type', self._var_name)
|
||||
return NO_CONTEXTS
|
||||
|
||||
@property
|
||||
|
||||
@@ -256,14 +256,18 @@ def _infer_type_vars_for_execution(execution_context, annotation_dict):
|
||||
annotation_node = annotation_dict[executed_param.string_name]
|
||||
except KeyError:
|
||||
continue
|
||||
if executed_param._param_node.star_count: # TODO remove this.
|
||||
continue
|
||||
|
||||
annotation_variables = find_unknown_type_vars(context, annotation_node)
|
||||
if annotation_variables:
|
||||
# Infer unknown type var
|
||||
annotation_context_set = context.eval_node(annotation_node)
|
||||
star_count = executed_param._param_node.star_count
|
||||
actual_context_set = executed_param.infer(use_hints=False)
|
||||
if star_count == 1:
|
||||
actual_context_set = actual_context_set.merge_types_of_iterate()
|
||||
elif star_count == 2:
|
||||
# TODO _dict_values is not public.
|
||||
actual_context_set = actual_context_set.try_merge('_dict_values')
|
||||
for ann in annotation_context_set:
|
||||
_merge_type_var_dicts(
|
||||
annotation_variable_results,
|
||||
|
||||
Reference in New Issue
Block a user