forked from VimPlug/jedi
Context -> Value
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from jedi._compatibility import unicode
|
||||
from jedi.inference.compiled.value import CompiledObject, CompiledName, \
|
||||
CompiledObjectFilter, CompiledContextName, create_from_access_path
|
||||
from jedi.inference.base_value import ContextWrapper, LazyContextWrapper
|
||||
CompiledObjectFilter, CompiledValueName, create_from_access_path
|
||||
from jedi.inference.base_value import ValueWrapper, LazyValueWrapper
|
||||
|
||||
|
||||
def builtin_from_name(infer_state, string):
|
||||
@@ -16,7 +16,7 @@ def builtin_from_name(infer_state, string):
|
||||
return value
|
||||
|
||||
|
||||
class CompiledValue(LazyContextWrapper):
|
||||
class CompiledValue(LazyValueWrapper):
|
||||
def __init__(self, compiled_obj):
|
||||
self.infer_state = compiled_obj.infer_state
|
||||
self._compiled_obj = compiled_obj
|
||||
|
||||
@@ -12,9 +12,9 @@ from jedi import settings
|
||||
from jedi.inference import compiled
|
||||
from jedi.cache import underscore_memoization
|
||||
from jedi.file_io import FileIO
|
||||
from jedi.inference.base_value import ContextSet, ContextWrapper
|
||||
from jedi.inference.base_value import ValueSet, ValueWrapper
|
||||
from jedi.inference.helpers import SimpleGetItemNotFound
|
||||
from jedi.inference.value import ModuleContext
|
||||
from jedi.inference.value import ModuleValue
|
||||
from jedi.inference.cache import infer_state_function_cache
|
||||
from jedi.inference.compiled.getattr_static import getattr_static
|
||||
from jedi.inference.compiled.access import compiled_objects_cache, \
|
||||
@@ -25,7 +25,7 @@ from jedi.inference.gradual.conversion import to_stub
|
||||
_sentinel = object()
|
||||
|
||||
|
||||
class MixedObject(ContextWrapper):
|
||||
class MixedObject(ValueWrapper):
|
||||
"""
|
||||
A ``MixedObject`` is used in two ways:
|
||||
|
||||
@@ -104,10 +104,10 @@ class MixedName(compiled.CompiledName):
|
||||
assert len(access_paths)
|
||||
values = [None]
|
||||
for access in access_paths:
|
||||
values = ContextSet.from_sets(
|
||||
values = ValueSet.from_sets(
|
||||
_create(self._infer_state, access, parent_value=c)
|
||||
if c is None or isinstance(c, MixedObject)
|
||||
else ContextSet({create_cached_compiled_object(c.infer_state, access, c)})
|
||||
else ValueSet({create_cached_compiled_object(c.infer_state, access, c)})
|
||||
for c in values
|
||||
)
|
||||
return values
|
||||
@@ -244,11 +244,11 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
if result is None:
|
||||
# TODO Care about generics from stuff like `[1]` and don't return like this.
|
||||
if type(python_object) in (dict, list, tuple):
|
||||
return ContextSet({compiled_object})
|
||||
return ValueSet({compiled_object})
|
||||
|
||||
tree_values = to_stub(compiled_object)
|
||||
if not tree_values:
|
||||
return ContextSet({compiled_object})
|
||||
return ValueSet({compiled_object})
|
||||
else:
|
||||
module_node, tree_node, file_io, code_lines = result
|
||||
|
||||
@@ -256,7 +256,7 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
# TODO this __name__ is probably wrong.
|
||||
name = compiled_object.get_root_value().py__name__()
|
||||
string_names = tuple(name.split('.'))
|
||||
module_value = ModuleContext(
|
||||
module_value = ModuleValue(
|
||||
infer_state, module_node,
|
||||
file_io=file_io,
|
||||
string_names=string_names,
|
||||
@@ -264,16 +264,16 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
is_package=hasattr(compiled_object, 'py__path__'),
|
||||
)
|
||||
if name is not None:
|
||||
infer_state.module_cache.add(string_names, ContextSet([module_value]))
|
||||
infer_state.module_cache.add(string_names, ValueSet([module_value]))
|
||||
else:
|
||||
if parent_value.tree_node.get_root_node() != module_node:
|
||||
# This happens e.g. when __module__ is wrong, or when using
|
||||
# TypeVar('foo'), where Jedi uses 'foo' as the name and
|
||||
# Python's TypeVar('foo').__module__ will be typing.
|
||||
return ContextSet({compiled_object})
|
||||
return ValueSet({compiled_object})
|
||||
module_value = parent_value.get_root_value()
|
||||
|
||||
tree_values = ContextSet({
|
||||
tree_values = ValueSet({
|
||||
module_value.create_value(
|
||||
tree_node,
|
||||
node_is_value=True,
|
||||
@@ -285,7 +285,7 @@ def _create(infer_state, access_handle, parent_value, *args):
|
||||
# Is an instance, not a class.
|
||||
tree_values = tree_values.execute_with_values()
|
||||
|
||||
return ContextSet(
|
||||
return ValueSet(
|
||||
MixedObject(compiled_object, tree_value=tree_value)
|
||||
for tree_value in tree_values
|
||||
)
|
||||
|
||||
@@ -9,10 +9,10 @@ from jedi.inference.utils import to_list
|
||||
from jedi._compatibility import force_unicode, Parameter, cast_path
|
||||
from jedi.cache import underscore_memoization, memoize_method
|
||||
from jedi.inference.filters import AbstractFilter
|
||||
from jedi.inference.names import AbstractNameDefinition, ContextNameMixin, \
|
||||
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
||||
ParamNameInterface
|
||||
from jedi.inference.base_value import Context, ContextSet, NO_VALUES
|
||||
from jedi.inference.lazy_value import LazyKnownContext
|
||||
from jedi.inference.base_value import Value, ValueSet, NO_VALUES
|
||||
from jedi.inference.lazy_value import LazyKnownValue
|
||||
from jedi.inference.compiled.access import _sentinel
|
||||
from jedi.inference.cache import infer_state_function_cache
|
||||
from jedi.inference.helpers import reraise_getitem_errors
|
||||
@@ -40,7 +40,7 @@ class CheckAttribute(object):
|
||||
return partial(self.func, instance)
|
||||
|
||||
|
||||
class CompiledObject(Context):
|
||||
class CompiledObject(Value):
|
||||
def __init__(self, infer_state, access_handle, parent_value=None):
|
||||
super(CompiledObject, self).__init__(infer_state, parent_value)
|
||||
self.access_handle = access_handle
|
||||
@@ -58,11 +58,11 @@ class CompiledObject(Context):
|
||||
else:
|
||||
if self.access_handle.is_class():
|
||||
from jedi.inference.value import CompiledInstance
|
||||
return ContextSet([
|
||||
return ValueSet([
|
||||
CompiledInstance(self.infer_state, self.parent_value, self, arguments)
|
||||
])
|
||||
else:
|
||||
return ContextSet(self._execute_function(arguments))
|
||||
return ValueSet(self._execute_function(arguments))
|
||||
|
||||
@CheckAttribute()
|
||||
def py__class__(self):
|
||||
@@ -187,7 +187,7 @@ class CompiledObject(Context):
|
||||
if access is None:
|
||||
return NO_VALUES
|
||||
|
||||
return ContextSet([create_from_access_path(self.infer_state, access)])
|
||||
return ValueSet([create_from_access_path(self.infer_state, access)])
|
||||
|
||||
def py__getitem__(self, index_value_set, valueualized_node):
|
||||
all_access_paths = self.access_handle.py__getitem__all_values()
|
||||
@@ -195,7 +195,7 @@ class CompiledObject(Context):
|
||||
# This means basically that no __getitem__ has been defined on this
|
||||
# object.
|
||||
return super(CompiledObject, self).py__getitem__(index_value_set, valueualized_node)
|
||||
return ContextSet(
|
||||
return ValueSet(
|
||||
create_from_access_path(self.infer_state, access)
|
||||
for access in all_access_paths
|
||||
)
|
||||
@@ -215,7 +215,7 @@ class CompiledObject(Context):
|
||||
return
|
||||
|
||||
for access in access_path_list:
|
||||
yield LazyKnownContext(create_from_access_path(self.infer_state, access))
|
||||
yield LazyKnownValue(create_from_access_path(self.infer_state, access))
|
||||
|
||||
def py__name__(self):
|
||||
return self.access_handle.py__name__()
|
||||
@@ -225,7 +225,7 @@ class CompiledObject(Context):
|
||||
name = self.py__name__()
|
||||
if name is None:
|
||||
name = self.access_handle.get_repr()
|
||||
return CompiledContextName(self, name)
|
||||
return CompiledValueName(self, name)
|
||||
|
||||
def _execute_function(self, params):
|
||||
from jedi.inference import docstrings
|
||||
@@ -295,7 +295,7 @@ class CompiledName(AbstractNameDefinition):
|
||||
|
||||
@underscore_memoization
|
||||
def infer(self):
|
||||
return ContextSet([_create_from_name(
|
||||
return ValueSet([_create_from_name(
|
||||
self._infer_state, self.parent_value, self.string_name
|
||||
)])
|
||||
|
||||
@@ -325,7 +325,7 @@ class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
infer_state = self.parent_value.infer_state
|
||||
values = NO_VALUES
|
||||
if p.has_default:
|
||||
values = ContextSet([create_from_access_path(infer_state, p.default)])
|
||||
values = ValueSet([create_from_access_path(infer_state, p.default)])
|
||||
if p.has_annotation:
|
||||
annotation = create_from_access_path(infer_state, p.annotation)
|
||||
values |= annotation.execute_with_values()
|
||||
@@ -351,7 +351,7 @@ class UnresolvableParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
return NO_VALUES
|
||||
|
||||
|
||||
class CompiledContextName(ContextNameMixin, AbstractNameDefinition):
|
||||
class CompiledValueName(ValueNameMixin, AbstractNameDefinition):
|
||||
def __init__(self, value, name):
|
||||
self.string_name = name
|
||||
self._value = value
|
||||
|
||||
Reference in New Issue
Block a user