forked from VimPlug/jedi
Deal with inheritance properly when dealing with function executions
This commit is contained in:
@@ -454,14 +454,14 @@ def get_global_filters(context, until_position, origin_scope):
|
|||||||
[...]
|
[...]
|
||||||
"""
|
"""
|
||||||
base_context = context
|
base_context = context
|
||||||
from jedi.inference.value.function import FunctionExecutionContext
|
from jedi.inference.value.function import BaseFunctionExecutionContext
|
||||||
while context is not None:
|
while context is not None:
|
||||||
# Names in methods cannot be resolved within the class.
|
# Names in methods cannot be resolved within the class.
|
||||||
for filter in context.get_filters(
|
for filter in context.get_filters(
|
||||||
until_position=until_position,
|
until_position=until_position,
|
||||||
origin_scope=origin_scope):
|
origin_scope=origin_scope):
|
||||||
yield filter
|
yield filter
|
||||||
if isinstance(context, FunctionExecutionContext):
|
if isinstance(context, BaseFunctionExecutionContext):
|
||||||
# The position should be reset if the current scope is a function.
|
# The position should be reset if the current scope is a function.
|
||||||
until_position = None
|
until_position = None
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ def _get_potential_nodes(module_value, func_string_name):
|
|||||||
|
|
||||||
|
|
||||||
def _check_name_for_execution(inference_state, context, compare_node, name, trailer):
|
def _check_name_for_execution(inference_state, context, compare_node, name, trailer):
|
||||||
from jedi.inference.value.function import FunctionExecutionContext
|
from jedi.inference.value.function import BaseFunctionExecutionContext
|
||||||
|
|
||||||
def create_func_excs(value):
|
def create_func_excs(value):
|
||||||
arglist = trailer.children[1]
|
arglist = trailer.children[1]
|
||||||
@@ -203,8 +203,8 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai
|
|||||||
for func_execution in create_func_excs(value):
|
for func_execution in create_func_excs(value):
|
||||||
# TODO private access
|
# TODO private access
|
||||||
yield func_execution._arguments
|
yield func_execution._arguments
|
||||||
elif isinstance(value.parent_context, FunctionExecutionContext) and \
|
elif isinstance(value.parent_context, BaseFunctionExecutionContext) \
|
||||||
compare_node.type == 'funcdef':
|
and compare_node.type == 'funcdef':
|
||||||
# Here we're trying to find decorators by checking the first
|
# Here we're trying to find decorators by checking the first
|
||||||
# parameter. It's not very generic though. Should find a better
|
# parameter. It's not very generic though. Should find a better
|
||||||
# solution that also applies to nested decorators.
|
# solution that also applies to nested decorators.
|
||||||
|
|||||||
@@ -160,11 +160,7 @@ class MethodValue(FunctionValue):
|
|||||||
return names + (self.py__name__(),)
|
return names + (self.py__name__(),)
|
||||||
|
|
||||||
|
|
||||||
class FunctionExecutionContext(ValueContext, TreeContextMixin):
|
class BaseFunctionExecutionContext(ValueContext, TreeContextMixin):
|
||||||
def __init__(self, function_value, arguments):
|
|
||||||
super(FunctionExecutionContext, self).__init__(function_value)
|
|
||||||
self._arguments = arguments
|
|
||||||
|
|
||||||
@inference_state_method_cache(default=NO_VALUES)
|
@inference_state_method_cache(default=NO_VALUES)
|
||||||
@recursion.execution_recursion_decorator()
|
@recursion.execution_recursion_decorator()
|
||||||
def get_return_values(self, check_yields=False):
|
def get_return_values(self, check_yields=False):
|
||||||
@@ -278,14 +274,6 @@ class FunctionExecutionContext(ValueContext, TreeContextMixin):
|
|||||||
for lazy_value in self.get_yield_lazy_values()
|
for lazy_value in self.get_yield_lazy_values()
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_filters(self, until_position=None, origin_scope=None):
|
|
||||||
yield FunctionExecutionFilter(
|
|
||||||
self, self._value,
|
|
||||||
until_position=until_position,
|
|
||||||
origin_scope=origin_scope,
|
|
||||||
arguments=self._arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
"""
|
"""
|
||||||
Created to be used by inheritance.
|
Created to be used by inheritance.
|
||||||
@@ -326,6 +314,20 @@ class FunctionExecutionContext(ValueContext, TreeContextMixin):
|
|||||||
else:
|
else:
|
||||||
return self.get_return_values()
|
return self.get_return_values()
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionExecutionContext(BaseFunctionExecutionContext):
|
||||||
|
def __init__(self, function_value, arguments):
|
||||||
|
super(FunctionExecutionContext, self).__init__(function_value)
|
||||||
|
self._arguments = arguments
|
||||||
|
|
||||||
|
def get_filters(self, until_position=None, origin_scope=None):
|
||||||
|
yield FunctionExecutionFilter(
|
||||||
|
self, self._value,
|
||||||
|
until_position=until_position,
|
||||||
|
origin_scope=origin_scope,
|
||||||
|
arguments=self._arguments
|
||||||
|
)
|
||||||
|
|
||||||
def get_param_names(self):
|
def get_param_names(self):
|
||||||
return [
|
return [
|
||||||
ParamName(self._value, param.name, self._arguments)
|
ParamName(self._value, param.name, self._arguments)
|
||||||
@@ -333,10 +335,7 @@ class FunctionExecutionContext(ValueContext, TreeContextMixin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class AnonymousFunctionExecution(FunctionExecutionContext):
|
class AnonymousFunctionExecution(BaseFunctionExecutionContext):
|
||||||
def __init__(self, function_value):
|
|
||||||
super(AnonymousFunctionExecution, self).__init__(function_value, arguments=None)
|
|
||||||
|
|
||||||
def get_filters(self, until_position=None, origin_scope=None):
|
def get_filters(self, until_position=None, origin_scope=None):
|
||||||
yield FunctionExecutionFilter(
|
yield FunctionExecutionFilter(
|
||||||
self, self._value,
|
self, self._value,
|
||||||
|
|||||||
Reference in New Issue
Block a user