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
@memoize_method
def as_context(self):
return self._as_context()
def as_context(self, *args, **kwargs):
return self._as_context(*args, **kwargs)
class Value(HelperValueMixin, BaseValue):

View File

@@ -227,7 +227,7 @@ def _infer_for_statement_string(module_context, string):
module_context,
funcdef
)
func_execution_context = function_value.get_function_execution()
func_execution_context = function_value.as_context()
# Use the module of the param.
# 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.

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():
yield execution
else:
yield value.get_function_execution(args)
yield value.as_context(args)
for value in inference_state.goto_definitions(context, name):
value_node = value.tree_node

View File

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

View File

@@ -197,7 +197,7 @@ class AbstractInstanceValue(Value):
name.tree_name.parent
)
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()
def create_instance_context(self, class_context, node):
@@ -215,9 +215,9 @@ class AbstractInstanceValue(Value):
)
bound_method = BoundMethod(self, func)
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:
return bound_method.get_function_execution()
return bound_method.as_context()
elif scope.type == 'classdef':
class_context = ClassValue(self.inference_state, parent_context, scope)
return class_context.as_context()
@@ -286,7 +286,7 @@ class TreeInstance(AbstractInstanceValue):
# Just take the first result, it should always be one, because we
# control the typeshed code.
bound = BoundMethod(self, func)
execution = bound.get_function_execution(self.var_args)
execution = bound.as_context(self.var_args)
if not execution.matches_signature():
# First check if the signature even matches, if not we don't
# need to infer anything.
@@ -404,15 +404,15 @@ class BoundMethod(FunctionMixin, ValueWrapper):
return InstanceArguments(self.instance, arguments)
def get_function_execution(self, arguments=None):
def as_context(self, arguments=None):
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):
if isinstance(self._wrapped_value, OverloadedFunctionValue):
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()
def get_signature_functions(self):