forked from VimPlug/jedi
Start using AnonymousMethodExecutionContext instead of the normal function execution context with arguments
This commit is contained in:
@@ -152,7 +152,7 @@ class _FunctionExecutionFilter(ParserTreeFilter):
|
|||||||
)
|
)
|
||||||
self._function_value = function_value
|
self._function_value = function_value
|
||||||
|
|
||||||
def _convert_param(self, name):
|
def _convert_param(self, param, name):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@to_list
|
@to_list
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from jedi.inference.value.module import ModuleValue
|
from jedi.inference.value.module import ModuleValue
|
||||||
from jedi.inference.value.klass import ClassValue
|
from jedi.inference.value.klass import ClassValue
|
||||||
from jedi.inference.value.function import FunctionValue, \
|
from jedi.inference.value.function import FunctionValue, \
|
||||||
MethodValue, FunctionExecutionContext
|
MethodValue
|
||||||
from jedi.inference.value.instance import AnonymousInstance, BoundMethod, \
|
from jedi.inference.value.instance import AnonymousInstance, BoundMethod, \
|
||||||
CompiledInstance, AbstractInstanceValue, TreeInstance
|
CompiledInstance, AbstractInstanceValue, TreeInstance
|
||||||
|
|||||||
@@ -68,13 +68,17 @@ class AnonymousMethodExecutionFilter(AnonymousFunctionExecutionFilter):
|
|||||||
def _convert_param(self, param, name):
|
def _convert_param(self, param, name):
|
||||||
if param.position_index == 0:
|
if param.position_index == 0:
|
||||||
return InstanceExecutedParamName(self._instance, self._function_value, name)
|
return InstanceExecutedParamName(self._instance, self._function_value, name)
|
||||||
return super(AnonymousFunctionExecutionFilter, self)._convert_param(param, name)
|
return super(AnonymousMethodExecutionFilter, self)._convert_param(param, name)
|
||||||
|
|
||||||
|
|
||||||
class AnonymousMethodExecutionContext(BaseFunctionExecutionContext):
|
class AnonymousMethodExecutionContext(BaseFunctionExecutionContext):
|
||||||
|
def __init__(self, instance, value):
|
||||||
|
super(AnonymousMethodExecutionContext, self).__init__(value)
|
||||||
|
self.instance = instance
|
||||||
|
|
||||||
def get_filters(self, until_position=None, origin_scope=None):
|
def get_filters(self, until_position=None, origin_scope=None):
|
||||||
yield AnonymousFunctionExecutionFilter(
|
yield AnonymousMethodExecutionFilter(
|
||||||
self, self._value,
|
self.instance, self, self._value,
|
||||||
until_position=until_position,
|
until_position=until_position,
|
||||||
origin_scope=origin_scope,
|
origin_scope=origin_scope,
|
||||||
)
|
)
|
||||||
@@ -83,7 +87,7 @@ class AnonymousMethodExecutionContext(BaseFunctionExecutionContext):
|
|||||||
param_names = list(self._value.get_param_names())
|
param_names = list(self._value.get_param_names())
|
||||||
# set the self name
|
# set the self name
|
||||||
param_names[0] = InstanceExecutedParamName(
|
param_names[0] = InstanceExecutedParamName(
|
||||||
self._instance,
|
self.instance,
|
||||||
self._function_value,
|
self._function_value,
|
||||||
param_names[0].tree_name
|
param_names[0].tree_name
|
||||||
)
|
)
|
||||||
@@ -469,6 +473,9 @@ class BoundMethod(FunctionMixin, ValueWrapper):
|
|||||||
return InstanceArguments(self.instance, arguments)
|
return InstanceArguments(self.instance, arguments)
|
||||||
|
|
||||||
def as_context(self, arguments=None):
|
def as_context(self, arguments=None):
|
||||||
|
if arguments is None:
|
||||||
|
return AnonymousMethodExecutionContext(self.instance, self)
|
||||||
|
|
||||||
arguments = self._get_arguments(arguments)
|
arguments = self._get_arguments(arguments)
|
||||||
return super(BoundMethod, self).as_context(arguments)
|
return super(BoundMethod, self).as_context(arguments)
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ from jedi.inference.arguments import ValuesArguments, \
|
|||||||
repack_with_argument_clinic, AbstractArguments, TreeArgumentsWrapper
|
repack_with_argument_clinic, AbstractArguments, TreeArgumentsWrapper
|
||||||
from jedi.inference import analysis
|
from jedi.inference import analysis
|
||||||
from jedi.inference import compiled
|
from jedi.inference import compiled
|
||||||
from jedi.inference.value.instance import BoundMethod, InstanceArguments
|
from jedi.inference.value.instance import BoundMethod, InstanceArguments, \
|
||||||
|
AnonymousMethodExecutionContext
|
||||||
from jedi.inference.base_value import ContextualizedNode, \
|
from jedi.inference.base_value import ContextualizedNode, \
|
||||||
NO_VALUES, ValueSet, ValueWrapper, LazyValueWrapper
|
NO_VALUES, ValueSet, ValueWrapper, LazyValueWrapper
|
||||||
from jedi.inference.value import ClassValue, ModuleValue, \
|
from jedi.inference.value import ClassValue, ModuleValue
|
||||||
FunctionExecutionContext
|
|
||||||
from jedi.inference.value.klass import ClassMixin
|
from jedi.inference.value.klass import ClassMixin
|
||||||
from jedi.inference.value.function import FunctionMixin
|
from jedi.inference.value.function import FunctionMixin, BaseFunctionExecutionContext
|
||||||
from jedi.inference.value import iterable
|
from jedi.inference.value import iterable
|
||||||
from jedi.inference.lazy_value import LazyTreeValue, LazyKnownValue, \
|
from jedi.inference.lazy_value import LazyTreeValue, LazyKnownValue, \
|
||||||
LazyKnownValues
|
LazyKnownValues
|
||||||
@@ -269,12 +269,16 @@ class SuperInstance(LazyValueWrapper):
|
|||||||
|
|
||||||
@argument_clinic('[type[, obj]], /', want_context=True)
|
@argument_clinic('[type[, obj]], /', want_context=True)
|
||||||
def builtins_super(types, objects, context):
|
def builtins_super(types, objects, context):
|
||||||
if isinstance(context, FunctionExecutionContext):
|
if isinstance(context, BaseFunctionExecutionContext):
|
||||||
|
instance = None
|
||||||
|
if isinstance(context, AnonymousMethodExecutionContext):
|
||||||
|
instance = context.instance
|
||||||
# TODO _arguments should be private. make this different.
|
# TODO _arguments should be private. make this different.
|
||||||
if isinstance(context._arguments, InstanceArguments):
|
elif isinstance(getattr(context, '_arguments', None), InstanceArguments):
|
||||||
instance = context._arguments.instance
|
instance = context._arguments.instance
|
||||||
# TODO if a class is given it doesn't have to be the direct super
|
# TODO if a class is given it doesn't have to be the direct super
|
||||||
# class, it can be an anecestor from long ago.
|
# class, it can be an anecestor from long ago.
|
||||||
|
if instance is not None:
|
||||||
return ValueSet({SuperInstance(instance.inference_state, instance)})
|
return ValueSet({SuperInstance(instance.inference_state, instance)})
|
||||||
|
|
||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|||||||
Reference in New Issue
Block a user