forked from VimPlug/jedi
Get rid of InstanceFunctionExecution, because it's really not needed
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from abc import abstractproperty
|
from abc import abstractproperty
|
||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
from jedi import settings
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import filters
|
from jedi.evaluate import filters
|
||||||
from jedi.evaluate.base_context import Context, NO_CONTEXTS, ContextSet, \
|
from jedi.evaluate.base_context import Context, NO_CONTEXTS, ContextSet, \
|
||||||
@@ -15,27 +16,13 @@ from jedi.evaluate.context import iterable
|
|||||||
from jedi.parser_utils import get_parent_scope
|
from jedi.parser_utils import get_parent_scope
|
||||||
|
|
||||||
|
|
||||||
class BaseInstanceFunctionExecution(FunctionExecutionContext):
|
class AnonymousInstanceFunctionExecution(FunctionExecutionContext):
|
||||||
def __init__(self, instance, *args, **kwargs):
|
|
||||||
self.instance = instance
|
|
||||||
super(BaseInstanceFunctionExecution, self).__init__(
|
|
||||||
instance.evaluator, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class InstanceFunctionExecution(BaseInstanceFunctionExecution):
|
|
||||||
def __init__(self, instance, parent_context, function_context, var_args):
|
|
||||||
var_args = InstanceArguments(instance, var_args)
|
|
||||||
|
|
||||||
super(InstanceFunctionExecution, self).__init__(
|
|
||||||
instance, parent_context, function_context, var_args)
|
|
||||||
|
|
||||||
|
|
||||||
class AnonymousInstanceFunctionExecution(BaseInstanceFunctionExecution):
|
|
||||||
function_execution_filter = filters.AnonymousInstanceFunctionExecutionFilter
|
function_execution_filter = filters.AnonymousInstanceFunctionExecutionFilter
|
||||||
|
|
||||||
def __init__(self, instance, parent_context, function_context, var_args):
|
def __init__(self, instance, *args, **kwargs):
|
||||||
|
self.instance = instance
|
||||||
super(AnonymousInstanceFunctionExecution, self).__init__(
|
super(AnonymousInstanceFunctionExecution, self).__init__(
|
||||||
instance, parent_context, function_context, var_args)
|
instance.evaluator, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AbstractInstanceContext(Context):
|
class AbstractInstanceContext(Context):
|
||||||
@@ -43,7 +30,6 @@ class AbstractInstanceContext(Context):
|
|||||||
This class is used to evaluate instances.
|
This class is used to evaluate instances.
|
||||||
"""
|
"""
|
||||||
api_type = u'instance'
|
api_type = u'instance'
|
||||||
function_execution_cls = InstanceFunctionExecution
|
|
||||||
|
|
||||||
def __init__(self, evaluator, parent_context, class_context, var_args):
|
def __init__(self, evaluator, parent_context, class_context, var_args):
|
||||||
super(AbstractInstanceContext, self).__init__(evaluator, parent_context)
|
super(AbstractInstanceContext, self).__init__(evaluator, parent_context)
|
||||||
@@ -159,12 +145,7 @@ class AbstractInstanceContext(Context):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _create_init_execution(self, class_context, bound_method):
|
def _create_init_execution(self, class_context, bound_method):
|
||||||
return self.function_execution_cls(
|
return bound_method.get_function_execution(self.var_args)
|
||||||
self,
|
|
||||||
class_context.parent_context,
|
|
||||||
bound_method,
|
|
||||||
self.var_args
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_init_executions(self):
|
def create_init_executions(self):
|
||||||
for name in self.get_function_slot_names(u'__init__'):
|
for name in self.get_function_slot_names(u'__init__'):
|
||||||
@@ -211,16 +192,18 @@ class AbstractInstanceContext(Context):
|
|||||||
|
|
||||||
|
|
||||||
class CompiledInstance(AbstractInstanceContext):
|
class CompiledInstance(AbstractInstanceContext):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, evaluator, parent_context, class_context, var_args):
|
||||||
super(CompiledInstance, self).__init__(*args, **kwargs)
|
self._original_var_args = var_args
|
||||||
|
|
||||||
# I don't think that dynamic append lookups should happen here. That
|
# I don't think that dynamic append lookups should happen here. That
|
||||||
# sounds more like something that should go to py__iter__.
|
# sounds more like something that should go to py__iter__.
|
||||||
self._original_var_args = self.var_args
|
if class_context.py__name__() in ['list', 'set'] \
|
||||||
|
and parent_context.get_root_context() == evaluator.builtins_module:
|
||||||
if self.class_context.name.string_name in ['list', 'set'] \
|
|
||||||
and self.parent_context.get_root_context() == self.evaluator.builtins_module:
|
|
||||||
# compare the module path with the builtin name.
|
# compare the module path with the builtin name.
|
||||||
self.var_args = iterable.get_dynamic_array_instance(self)
|
if settings.dynamic_array_additions:
|
||||||
|
var_args = iterable.get_dynamic_array_instance(self, var_args)
|
||||||
|
|
||||||
|
super(CompiledInstance, self).__init__(evaluator, parent_context, class_context, var_args)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -252,8 +235,6 @@ class TreeInstance(AbstractInstanceContext):
|
|||||||
|
|
||||||
|
|
||||||
class AnonymousInstance(TreeInstance):
|
class AnonymousInstance(TreeInstance):
|
||||||
function_execution_cls = AnonymousInstanceFunctionExecution
|
|
||||||
|
|
||||||
def __init__(self, evaluator, parent_context, class_context):
|
def __init__(self, evaluator, parent_context, class_context):
|
||||||
super(AnonymousInstance, self).__init__(
|
super(AnonymousInstance, self).__init__(
|
||||||
evaluator,
|
evaluator,
|
||||||
@@ -262,6 +243,14 @@ class AnonymousInstance(TreeInstance):
|
|||||||
var_args=AnonymousArguments(),
|
var_args=AnonymousArguments(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _create_init_execution(self, class_context, bound_method):
|
||||||
|
return AnonymousInstanceFunctionExecution(
|
||||||
|
self,
|
||||||
|
class_context.parent_context,
|
||||||
|
bound_method,
|
||||||
|
self.var_args
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CompiledInstanceName(compiled.CompiledName):
|
class CompiledInstanceName(compiled.CompiledName):
|
||||||
|
|
||||||
|
|||||||
@@ -630,12 +630,9 @@ def _check_array_additions(context, sequence):
|
|||||||
return added_types
|
return added_types
|
||||||
|
|
||||||
|
|
||||||
def get_dynamic_array_instance(instance):
|
def get_dynamic_array_instance(instance, arguments):
|
||||||
"""Used for set() and list() instances."""
|
"""Used for set() and list() instances."""
|
||||||
if not settings.dynamic_array_additions:
|
ai = _ArrayInstance(instance, arguments)
|
||||||
return instance.var_args
|
|
||||||
|
|
||||||
ai = _ArrayInstance(instance)
|
|
||||||
from jedi.evaluate import arguments
|
from jedi.evaluate import arguments
|
||||||
return arguments.ValuesArguments([ContextSet(ai)])
|
return arguments.ValuesArguments([ContextSet(ai)])
|
||||||
|
|
||||||
@@ -651,9 +648,9 @@ class _ArrayInstance(object):
|
|||||||
and therefore doesn't need filters, `py__bool__` and so on, because
|
and therefore doesn't need filters, `py__bool__` and so on, because
|
||||||
we don't use these operations in `builtins.py`.
|
we don't use these operations in `builtins.py`.
|
||||||
"""
|
"""
|
||||||
def __init__(self, instance):
|
def __init__(self, instance, var_args):
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
self.var_args = instance.var_args
|
self.var_args = var_args
|
||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
var_args = self.var_args
|
var_args = self.var_args
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ def infer_param(execution_context, param):
|
|||||||
"Comments length != Params length %s %s",
|
"Comments length != Params length %s %s",
|
||||||
params_comments, all_params
|
params_comments, all_params
|
||||||
)
|
)
|
||||||
from jedi.evaluate.context.instance import BaseInstanceFunctionExecution
|
from jedi.evaluate.context.instance import InstanceArguments
|
||||||
if isinstance(execution_context, BaseInstanceFunctionExecution):
|
if isinstance(execution_context.var_args, InstanceArguments):
|
||||||
if index == 0:
|
if index == 0:
|
||||||
# Assume it's self, which is already handled
|
# Assume it's self, which is already handled
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ def eval_expr_stmt(context, stmt, seek_name=None):
|
|||||||
# necessary.
|
# necessary.
|
||||||
if not allowed and context.get_root_context() == context.evaluator.builtins_module:
|
if not allowed and context.get_root_context() == context.evaluator.builtins_module:
|
||||||
try:
|
try:
|
||||||
instance = context.instance
|
instance = context.var_args.instance
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user