1
0
forked from VimPlug/jedi

get_function_execution -> as_context

This commit is contained in:
Dave Halter
2019-08-24 11:11:00 +02:00
parent d913d7d701
commit e0f26dd7a1
5 changed files with 15 additions and 19 deletions

View File

@@ -134,8 +134,8 @@ class HelperValueMixin(object):
return self == class2 return self == class2
@memoize_method @memoize_method
def as_context(self): def as_context(self, *args, **kwargs):
return self._as_context() return self._as_context(*args, **kwargs)
class Value(HelperValueMixin, BaseValue): class Value(HelperValueMixin, BaseValue):

View File

@@ -227,7 +227,7 @@ def _infer_for_statement_string(module_context, string):
module_context, module_context,
funcdef funcdef
) )
func_execution_context = function_value.get_function_execution() func_execution_context = function_value.as_context()
# Use the module of the param. # Use the module of the param.
# TODO this module is not the module of the param in case of a function # TODO this module is not the module of the param in case of a function
# call. In that case it's the module of the function call. # call. In that case it's the module of the function call.

View File

@@ -194,7 +194,7 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai
for execution in created_instance.create_init_executions(): for execution in created_instance.create_init_executions():
yield execution yield execution
else: else:
yield value.get_function_execution(args) yield value.as_context(args)
for value in inference_state.goto_definitions(context, name): for value in inference_state.goto_definitions(context, name):
value_node = value.tree_node value_node = value.tree_node

View File

@@ -69,7 +69,7 @@ class FunctionMixin(object):
return ValueSet([BoundMethod(instance, self)]) return ValueSet([BoundMethod(instance, self)])
def get_param_names(self): def get_param_names(self):
function_execution = self.get_function_execution() function_execution = self.as_context()
return [ParamName(function_execution, param.name) return [ParamName(function_execution, param.name)
for param in self.tree_node.get_params()] for param in self.tree_node.get_params()]
@@ -83,18 +83,14 @@ class FunctionMixin(object):
return self.name.string_name return self.name.string_name
def py__call__(self, arguments): def py__call__(self, arguments):
function_execution = self.get_function_execution(arguments) function_execution = self.as_context(arguments)
return function_execution.infer() return function_execution.infer()
def get_function_execution(self, arguments=None): def _as_context(self, arguments=None):
if arguments is None: if arguments is None:
arguments = AnonymousArguments() arguments = AnonymousArguments()
return FunctionExecutionContext(self, arguments) return FunctionExecutionContext(self, arguments)
def _as_context(self):
return self.get_function_execution()
def get_signatures(self): def get_signatures(self):
return [TreeSignature(f) for f in self.get_signature_functions()] return [TreeSignature(f) for f in self.get_signature_functions()]
@@ -362,7 +358,7 @@ class OverloadedFunctionValue(FunctionMixin, ValueWrapper):
value_set = NO_VALUES value_set = NO_VALUES
matched = False matched = False
for f in self._overloaded_functions: for f in self._overloaded_functions:
function_execution = f.get_function_execution(arguments) function_execution = f.as_context(arguments)
function_executions.append(function_execution) function_executions.append(function_execution)
if function_execution.matches_signature(): if function_execution.matches_signature():
matched = True matched = True

View File

@@ -197,7 +197,7 @@ class AbstractInstanceValue(Value):
name.tree_name.parent name.tree_name.parent
) )
bound_method = BoundMethod(self, function) bound_method = BoundMethod(self, function)
yield bound_method.get_function_execution(self.var_args) yield bound_method.as_context(self.var_args)
@inference_state_method_cache() @inference_state_method_cache()
def create_instance_context(self, class_context, node): def create_instance_context(self, class_context, node):
@@ -215,9 +215,9 @@ class AbstractInstanceValue(Value):
) )
bound_method = BoundMethod(self, func) bound_method = BoundMethod(self, func)
if scope.name.value == '__init__' and parent_context == class_context: if scope.name.value == '__init__' and parent_context == class_context:
return bound_method.get_function_execution(self.var_args) return bound_method.as_context(self.var_args)
else: else:
return bound_method.get_function_execution() return bound_method.as_context()
elif scope.type == 'classdef': elif scope.type == 'classdef':
class_context = ClassValue(self.inference_state, parent_context, scope) class_context = ClassValue(self.inference_state, parent_context, scope)
return class_context.as_context() return class_context.as_context()
@@ -286,7 +286,7 @@ class TreeInstance(AbstractInstanceValue):
# Just take the first result, it should always be one, because we # Just take the first result, it should always be one, because we
# control the typeshed code. # control the typeshed code.
bound = BoundMethod(self, func) bound = BoundMethod(self, func)
execution = bound.get_function_execution(self.var_args) execution = bound.as_context(self.var_args)
if not execution.matches_signature(): if not execution.matches_signature():
# 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.
@@ -404,15 +404,15 @@ class BoundMethod(FunctionMixin, ValueWrapper):
return InstanceArguments(self.instance, arguments) return InstanceArguments(self.instance, arguments)
def get_function_execution(self, arguments=None): def as_context(self, arguments=None):
arguments = self._get_arguments(arguments) arguments = self._get_arguments(arguments)
return super(BoundMethod, self).get_function_execution(arguments) return super(BoundMethod, self).as_context(arguments)
def py__call__(self, arguments): def py__call__(self, arguments):
if isinstance(self._wrapped_value, OverloadedFunctionValue): if isinstance(self._wrapped_value, OverloadedFunctionValue):
return self._wrapped_value.py__call__(self._get_arguments(arguments)) return self._wrapped_value.py__call__(self._get_arguments(arguments))
function_execution = self.get_function_execution(arguments) function_execution = self.as_context(arguments)
return function_execution.infer() return function_execution.infer()
def get_signature_functions(self): def get_signature_functions(self):