forked from VimPlug/jedi
Context -> Value
This commit is contained in:
@@ -6,16 +6,16 @@ from jedi.inference import compiled
|
||||
from jedi.inference.compiled.value import CompiledObjectFilter
|
||||
from jedi.inference.helpers import values_from_qualified_names
|
||||
from jedi.inference.filters import AbstractFilter
|
||||
from jedi.inference.names import ContextName, TreeNameDefinition
|
||||
from jedi.inference.base_value import Context, NO_VALUES, ContextSet, \
|
||||
iterator_to_value_set, ContextWrapper
|
||||
from jedi.inference.lazy_value import LazyKnownContext, LazyKnownContexts
|
||||
from jedi.inference.names import ValueName, TreeNameDefinition
|
||||
from jedi.inference.base_value import Value, NO_VALUES, ValueSet, \
|
||||
iterator_to_value_set, ValueWrapper
|
||||
from jedi.inference.lazy_value import LazyKnownValue, LazyKnownValues
|
||||
from jedi.inference.cache import infer_state_method_cache
|
||||
from jedi.inference.arguments import AnonymousArguments, \
|
||||
ValuesArguments, TreeArgumentsWrapper
|
||||
from jedi.inference.value.function import \
|
||||
FunctionContext, FunctionMixin, OverloadedFunctionContext
|
||||
from jedi.inference.value.klass import ClassContext, apply_py__get__, \
|
||||
FunctionValue, FunctionMixin, OverloadedFunctionValue
|
||||
from jedi.inference.value.klass import ClassValue, apply_py__get__, \
|
||||
ClassFilter
|
||||
from jedi.inference.value import iterable
|
||||
from jedi.parser_utils import get_parent_scope
|
||||
@@ -28,7 +28,7 @@ class InstanceExecutedParam(object):
|
||||
self.string_name = self._tree_param.name.value
|
||||
|
||||
def infer(self):
|
||||
return ContextSet([self._instance])
|
||||
return ValueSet([self._instance])
|
||||
|
||||
def matches_signature(self):
|
||||
return True
|
||||
@@ -58,11 +58,11 @@ class AnonymousInstanceArguments(AnonymousArguments):
|
||||
return executed_params, []
|
||||
|
||||
|
||||
class AbstractInstanceContext(Context):
|
||||
class AbstractInstanceValue(Value):
|
||||
api_type = u'instance'
|
||||
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
super(AbstractInstanceContext, self).__init__(infer_state, parent_value)
|
||||
super(AbstractInstanceValue, self).__init__(infer_state, parent_value)
|
||||
# Generated instances are classes that are just generated by self
|
||||
# (No var_args) used.
|
||||
self.class_value = class_value
|
||||
@@ -81,9 +81,9 @@ class AbstractInstanceContext(Context):
|
||||
names = self.get_function_slot_names(u'__call__')
|
||||
if not names:
|
||||
# Means the Instance is not callable.
|
||||
return super(AbstractInstanceContext, self).py__call__(arguments)
|
||||
return super(AbstractInstanceValue, self).py__call__(arguments)
|
||||
|
||||
return ContextSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||
return ValueSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||
|
||||
def py__class__(self):
|
||||
return self.class_value
|
||||
@@ -103,7 +103,7 @@ class AbstractInstanceContext(Context):
|
||||
return []
|
||||
|
||||
def execute_function_slots(self, names, *inferred_args):
|
||||
return ContextSet.from_sets(
|
||||
return ValueSet.from_sets(
|
||||
name.infer().execute_with_values(*inferred_args)
|
||||
for name in names
|
||||
)
|
||||
@@ -120,7 +120,7 @@ class AbstractInstanceContext(Context):
|
||||
obj = compiled.builtin_from_name(self.infer_state, u'None')
|
||||
return self.execute_function_slots(names, obj, class_value)
|
||||
else:
|
||||
return ContextSet([self])
|
||||
return ValueSet([self])
|
||||
|
||||
def get_filters(self, search_global=None, until_position=None,
|
||||
origin_scope=None, include_self_names=True):
|
||||
@@ -151,18 +151,18 @@ class AbstractInstanceContext(Context):
|
||||
def py__getitem__(self, index_value_set, valueualized_node):
|
||||
names = self.get_function_slot_names(u'__getitem__')
|
||||
if not names:
|
||||
return super(AbstractInstanceContext, self).py__getitem__(
|
||||
return super(AbstractInstanceValue, self).py__getitem__(
|
||||
index_value_set,
|
||||
valueualized_node,
|
||||
)
|
||||
|
||||
args = ValuesArguments([index_value_set])
|
||||
return ContextSet.from_sets(name.infer().execute(args) for name in names)
|
||||
return ValueSet.from_sets(name.infer().execute(args) for name in names)
|
||||
|
||||
def py__iter__(self, valueualized_node=None):
|
||||
iter_slot_names = self.get_function_slot_names(u'__iter__')
|
||||
if not iter_slot_names:
|
||||
return super(AbstractInstanceContext, self).py__iter__(valueualized_node)
|
||||
return super(AbstractInstanceValue, self).py__iter__(valueualized_node)
|
||||
|
||||
def iterate():
|
||||
for generator in self.execute_function_slots(iter_slot_names):
|
||||
@@ -174,7 +174,7 @@ class AbstractInstanceContext(Context):
|
||||
name = u'__next__'
|
||||
next_slot_names = generator.get_function_slot_names(name)
|
||||
if next_slot_names:
|
||||
yield LazyKnownContexts(
|
||||
yield LazyKnownValues(
|
||||
generator.execute_function_slots(next_slot_names)
|
||||
)
|
||||
else:
|
||||
@@ -192,7 +192,7 @@ class AbstractInstanceContext(Context):
|
||||
for name in self.get_function_slot_names(u'__init__'):
|
||||
# TODO is this correct? I think we need to check for functions.
|
||||
if isinstance(name, LazyInstanceClassName):
|
||||
function = FunctionContext.from_value(
|
||||
function = FunctionValue.from_value(
|
||||
self.parent_value,
|
||||
name.tree_name.parent
|
||||
)
|
||||
@@ -209,7 +209,7 @@ class AbstractInstanceContext(Context):
|
||||
else:
|
||||
parent_value = self.create_instance_value(class_value, scope)
|
||||
if scope.type == 'funcdef':
|
||||
func = FunctionContext.from_value(
|
||||
func = FunctionValue.from_value(
|
||||
parent_value,
|
||||
scope,
|
||||
)
|
||||
@@ -219,7 +219,7 @@ class AbstractInstanceContext(Context):
|
||||
else:
|
||||
return bound_method.get_function_execution()
|
||||
elif scope.type == 'classdef':
|
||||
class_value = ClassContext(self.infer_state, parent_value, scope)
|
||||
class_value = ClassValue(self.infer_state, parent_value, scope)
|
||||
return class_value
|
||||
elif scope.type in ('comp_for', 'sync_comp_for'):
|
||||
# Comprehensions currently don't have a special scope in Jedi.
|
||||
@@ -237,14 +237,14 @@ class AbstractInstanceContext(Context):
|
||||
self.var_args)
|
||||
|
||||
|
||||
class CompiledInstance(AbstractInstanceContext):
|
||||
class CompiledInstance(AbstractInstanceValue):
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
self._original_var_args = var_args
|
||||
super(CompiledInstance, self).__init__(infer_state, parent_value, class_value, var_args)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return compiled.CompiledContextName(self, self.class_value.name.string_name)
|
||||
return compiled.CompiledValueName(self, self.class_value.name.string_name)
|
||||
|
||||
def get_first_non_keyword_argument_values(self):
|
||||
key, lazy_value = next(self._original_var_args.unpack(), ('', None))
|
||||
@@ -257,7 +257,7 @@ class CompiledInstance(AbstractInstanceContext):
|
||||
return False
|
||||
|
||||
|
||||
class TreeInstance(AbstractInstanceContext):
|
||||
class TreeInstance(AbstractInstanceValue):
|
||||
def __init__(self, infer_state, parent_value, class_value, var_args):
|
||||
# I don't think that dynamic append lookups should happen here. That
|
||||
# sounds more like something that should go to py__iter__.
|
||||
@@ -273,7 +273,7 @@ class TreeInstance(AbstractInstanceContext):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return ContextName(self, self.class_value.name.tree_name)
|
||||
return ValueName(self, self.class_value.name.tree_name)
|
||||
|
||||
# This can recurse, if the initialization of the class includes a reference
|
||||
# to itself.
|
||||
@@ -367,7 +367,7 @@ class CompiledInstanceClassFilter(AbstractFilter):
|
||||
]
|
||||
|
||||
|
||||
class BoundMethod(FunctionMixin, ContextWrapper):
|
||||
class BoundMethod(FunctionMixin, ValueWrapper):
|
||||
def __init__(self, instance, function):
|
||||
super(BoundMethod, self).__init__(function)
|
||||
self.instance = instance
|
||||
@@ -390,7 +390,7 @@ class BoundMethod(FunctionMixin, ContextWrapper):
|
||||
return super(BoundMethod, self).get_function_execution(arguments)
|
||||
|
||||
def py__call__(self, arguments):
|
||||
if isinstance(self._wrapped_value, OverloadedFunctionContext):
|
||||
if isinstance(self._wrapped_value, OverloadedFunctionValue):
|
||||
return self._wrapped_value.py__call__(self._get_arguments(arguments))
|
||||
|
||||
function_execution = self.get_function_execution(arguments)
|
||||
@@ -409,7 +409,7 @@ class BoundMethod(FunctionMixin, ContextWrapper):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self._wrapped_value)
|
||||
|
||||
|
||||
class CompiledBoundMethod(ContextWrapper):
|
||||
class CompiledBoundMethod(ValueWrapper):
|
||||
def is_bound_method(self):
|
||||
return True
|
||||
|
||||
@@ -517,7 +517,7 @@ class InstanceArguments(TreeArgumentsWrapper):
|
||||
self.instance = instance
|
||||
|
||||
def unpack(self, func=None):
|
||||
yield None, LazyKnownContext(self.instance)
|
||||
yield None, LazyKnownValue(self.instance)
|
||||
for values in self._wrapped_arguments.unpack(func):
|
||||
yield values
|
||||
|
||||
|
||||
Reference in New Issue
Block a user