forked from VimPlug/jedi
Fix inferring dict.values()
This commit is contained in:
@@ -300,6 +300,17 @@ class ContextSet(BaseContextSet):
|
|||||||
def get_item(self, *args, **kwargs):
|
def get_item(self, *args, **kwargs):
|
||||||
return ContextSet.from_sets(_getitem(c, *args, **kwargs) for c in self._set)
|
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()
|
NO_CONTEXTS = ContextSet()
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, AbstractFunction)):
|
|||||||
|
|
||||||
def py__call__(self, arguments, need_param_match=False):
|
def py__call__(self, arguments, need_param_match=False):
|
||||||
function_execution = self.get_function_execution(arguments)
|
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 NO_CONTEXTS
|
||||||
return function_execution.infer()
|
return function_execution.infer()
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,6 @@ class TreeInstance(AbstractInstanceContext):
|
|||||||
# First check if the signature even matches, if not we don't
|
# First check if the signature even matches, if not we don't
|
||||||
# need to infer anything.
|
# need to infer anything.
|
||||||
continue
|
continue
|
||||||
print(bound)
|
|
||||||
context_set = define_type_vars_for_execution(
|
context_set = define_type_vars_for_execution(
|
||||||
ContextSet(self.class_context),
|
ContextSet(self.class_context),
|
||||||
execution,
|
execution,
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ class TypeVar(_BaseTypingContext):
|
|||||||
return ContextSet.from_sets(
|
return ContextSet.from_sets(
|
||||||
l.infer() for l in self._constraints_lazy_contexts
|
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
|
return NO_CONTEXTS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -256,14 +256,18 @@ def _infer_type_vars_for_execution(execution_context, annotation_dict):
|
|||||||
annotation_node = annotation_dict[executed_param.string_name]
|
annotation_node = annotation_dict[executed_param.string_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
if executed_param._param_node.star_count: # TODO remove this.
|
|
||||||
continue
|
|
||||||
|
|
||||||
annotation_variables = find_unknown_type_vars(context, annotation_node)
|
annotation_variables = find_unknown_type_vars(context, annotation_node)
|
||||||
if annotation_variables:
|
if annotation_variables:
|
||||||
# Infer unknown type var
|
# Infer unknown type var
|
||||||
annotation_context_set = context.eval_node(annotation_node)
|
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)
|
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:
|
for ann in annotation_context_set:
|
||||||
_merge_type_var_dicts(
|
_merge_type_var_dicts(
|
||||||
annotation_variable_results,
|
annotation_variable_results,
|
||||||
|
|||||||
Reference in New Issue
Block a user