forked from VimPlug/jedi
CompiledObject -> CompiledValue
This commit is contained in:
@@ -18,7 +18,7 @@ def try_iter_content(types, depth=0):
|
|||||||
"""Helper method for static analysis."""
|
"""Helper method for static analysis."""
|
||||||
if depth > 10:
|
if depth > 10:
|
||||||
# It's possible that a loop has references on itself (especially with
|
# It's possible that a loop has references on itself (especially with
|
||||||
# CompiledObject). Therefore don't loop infinitely.
|
# CompiledValue). Therefore don't loop infinitely.
|
||||||
return
|
return
|
||||||
|
|
||||||
for typ in types:
|
for typ in types:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi.inference.compiled.value import CompiledObject, CompiledName, \
|
from jedi.inference.compiled.value import CompiledValue, CompiledName, \
|
||||||
CompiledObjectFilter, CompiledValueName, create_from_access_path
|
CompiledValueFilter, CompiledValueName, create_from_access_path
|
||||||
from jedi.inference.base_value import LazyValueWrapper
|
from jedi.inference.base_value import LazyValueWrapper
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ class MixedObject(ValueWrapper):
|
|||||||
|
|
||||||
1. It uses the default logic of ``parser.python.tree`` objects,
|
1. It uses the default logic of ``parser.python.tree`` objects,
|
||||||
2. except for getattr calls and signatures. The names dicts are generated
|
2. except for getattr calls and signatures. The names dicts are generated
|
||||||
in a fashion like ``CompiledObject``.
|
in a fashion like ``CompiledValue``.
|
||||||
|
|
||||||
This combined logic makes it possible to provide more powerful REPL
|
This combined logic makes it possible to provide more powerful REPL
|
||||||
completion. It allows side effects that are not noticable with the default
|
completion. It allows side effects that are not noticable with the default
|
||||||
parser structure to still be completeable.
|
parser structure to still be completeable.
|
||||||
|
|
||||||
The biggest difference from CompiledObject to MixedObject is that we are
|
The biggest difference from CompiledValue to MixedObject is that we are
|
||||||
generally dealing with Python code and not with C code. This will generate
|
generally dealing with Python code and not with C code. This will generate
|
||||||
fewer special cases, because we in Python you don't have the same freedoms
|
fewer special cases, because we in Python you don't have the same freedoms
|
||||||
to modify the runtime.
|
to modify the runtime.
|
||||||
@@ -129,7 +129,7 @@ class MixedName(NameWrapper):
|
|||||||
return _create(self._inference_state, compiled_object, module_context)
|
return _create(self._inference_state, compiled_object, module_context)
|
||||||
|
|
||||||
|
|
||||||
class MixedObjectFilter(compiled.CompiledObjectFilter):
|
class MixedObjectFilter(compiled.CompiledValueFilter):
|
||||||
def __init__(self, inference_state, compiled_object, tree_value):
|
def __init__(self, inference_state, compiled_object, tree_value):
|
||||||
super(MixedObjectFilter, self).__init__(inference_state, compiled_object)
|
super(MixedObjectFilter, self).__init__(inference_state, compiled_object)
|
||||||
self._tree_value = tree_value
|
self._tree_value = tree_value
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ class CheckAttribute(object):
|
|||||||
return partial(self.func, instance)
|
return partial(self.func, instance)
|
||||||
|
|
||||||
|
|
||||||
class CompiledObject(Value):
|
class CompiledValue(Value):
|
||||||
def __init__(self, inference_state, access_handle, parent_context=None):
|
def __init__(self, inference_state, access_handle, parent_context=None):
|
||||||
super(CompiledObject, self).__init__(inference_state, parent_context)
|
super(CompiledValue, self).__init__(inference_state, parent_context)
|
||||||
self.access_handle = access_handle
|
self.access_handle = access_handle
|
||||||
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
@@ -58,7 +58,7 @@ class CompiledObject(Value):
|
|||||||
try:
|
try:
|
||||||
self.access_handle.getattr_paths(u'__call__')
|
self.access_handle.getattr_paths(u'__call__')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return super(CompiledObject, self).py__call__(arguments)
|
return super(CompiledValue, self).py__call__(arguments)
|
||||||
else:
|
else:
|
||||||
if self.access_handle.is_class():
|
if self.access_handle.is_class():
|
||||||
from jedi.inference.value import CompiledInstance
|
from jedi.inference.value import CompiledInstance
|
||||||
@@ -156,14 +156,14 @@ class CompiledObject(Value):
|
|||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def _ensure_one_filter(self, is_instance):
|
def _ensure_one_filter(self, is_instance):
|
||||||
return CompiledObjectFilter(self.inference_state, self, is_instance)
|
return CompiledValueFilter(self.inference_state, self, is_instance)
|
||||||
|
|
||||||
def py__simple_getitem__(self, index):
|
def py__simple_getitem__(self, index):
|
||||||
with reraise_getitem_errors(IndexError, KeyError, TypeError):
|
with reraise_getitem_errors(IndexError, KeyError, TypeError):
|
||||||
try:
|
try:
|
||||||
access = self.access_handle.py__simple_getitem__(index)
|
access = self.access_handle.py__simple_getitem__(index)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return super(CompiledObject, self).py__simple_getitem__(index)
|
return super(CompiledValue, self).py__simple_getitem__(index)
|
||||||
if access is None:
|
if access is None:
|
||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ class CompiledObject(Value):
|
|||||||
if all_access_paths is None:
|
if all_access_paths is None:
|
||||||
# This means basically that no __getitem__ has been defined on this
|
# This means basically that no __getitem__ has been defined on this
|
||||||
# object.
|
# object.
|
||||||
return super(CompiledObject, self).py__getitem__(index_value_set, contextualized_node)
|
return super(CompiledValue, self).py__getitem__(index_value_set, contextualized_node)
|
||||||
return ValueSet(
|
return ValueSet(
|
||||||
create_from_access_path(self.inference_state, access)
|
create_from_access_path(self.inference_state, access)
|
||||||
for access in all_access_paths
|
for access in all_access_paths
|
||||||
@@ -186,7 +186,7 @@ class CompiledObject(Value):
|
|||||||
# just start with __getitem__(0). This is especially true for
|
# just start with __getitem__(0). This is especially true for
|
||||||
# Python 2 strings, where `str.__iter__` is not even defined.
|
# Python 2 strings, where `str.__iter__` is not even defined.
|
||||||
if not self.access_handle.has_iter():
|
if not self.access_handle.has_iter():
|
||||||
for x in super(CompiledObject, self).py__iter__(contextualized_node):
|
for x in super(CompiledValue, self).py__iter__(contextualized_node):
|
||||||
yield x
|
yield x
|
||||||
|
|
||||||
access_path_list = self.access_handle.py__iter__list()
|
access_path_list = self.access_handle.py__iter__list()
|
||||||
@@ -264,7 +264,7 @@ class CompiledObject(Value):
|
|||||||
v.with_generics(arguments)
|
v.with_generics(arguments)
|
||||||
for v in self.inference_state.typing_module.py__getattribute__(name)
|
for v in self.inference_state.typing_module.py__getattribute__(name)
|
||||||
]).execute_annotation()
|
]).execute_annotation()
|
||||||
return super(CompiledObject, self).execute_annotation()
|
return super(CompiledValue, self).execute_annotation()
|
||||||
|
|
||||||
def negate(self):
|
def negate(self):
|
||||||
return create_from_access_path(self.inference_state, self.access_handle.negate())
|
return create_from_access_path(self.inference_state, self.access_handle.negate())
|
||||||
@@ -286,7 +286,7 @@ class CompiledObject(Value):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CompiledModule(CompiledObject):
|
class CompiledModule(CompiledValue):
|
||||||
file_io = None # For modules
|
file_io = None # For modules
|
||||||
|
|
||||||
def _as_context(self):
|
def _as_context(self):
|
||||||
@@ -432,7 +432,7 @@ class EmptyCompiledName(AbstractNameDefinition):
|
|||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|
||||||
|
|
||||||
class CompiledObjectFilter(AbstractFilter):
|
class CompiledValueFilter(AbstractFilter):
|
||||||
def __init__(self, inference_state, compiled_object, is_instance=False):
|
def __init__(self, inference_state, compiled_object, is_instance=False):
|
||||||
self._inference_state = inference_state
|
self._inference_state = inference_state
|
||||||
self.compiled_object = compiled_object
|
self.compiled_object = compiled_object
|
||||||
@@ -619,9 +619,9 @@ def create_from_access_path(inference_state, access_path):
|
|||||||
@_normalize_create_args
|
@_normalize_create_args
|
||||||
@inference_state_function_cache()
|
@inference_state_function_cache()
|
||||||
def create_cached_compiled_object(inference_state, access_handle, parent_context):
|
def create_cached_compiled_object(inference_state, access_handle, parent_context):
|
||||||
assert not isinstance(parent_context, CompiledObject)
|
assert not isinstance(parent_context, CompiledValue)
|
||||||
if parent_context is None:
|
if parent_context is None:
|
||||||
cls = CompiledModule
|
cls = CompiledModule
|
||||||
else:
|
else:
|
||||||
cls = CompiledObject
|
cls = CompiledValue
|
||||||
return cls(inference_state, access_handle, parent_context)
|
return cls(inference_state, access_handle, parent_context)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from parso.python.tree import search_ancestor
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.inference import compiled
|
from jedi.inference import compiled
|
||||||
from jedi.inference.compiled.value import CompiledObjectFilter
|
from jedi.inference.compiled.value import CompiledValueFilter
|
||||||
from jedi.inference.helpers import values_from_qualified_names, is_big_annoying_library
|
from jedi.inference.helpers import values_from_qualified_names, is_big_annoying_library
|
||||||
from jedi.inference.filters import AbstractFilter, AnonymousFunctionExecutionFilter
|
from jedi.inference.filters import AbstractFilter, AnonymousFunctionExecutionFilter
|
||||||
from jedi.inference.names import ValueName, TreeNameDefinition, ParamName, \
|
from jedi.inference.names import ValueName, TreeNameDefinition, ParamName, \
|
||||||
@@ -189,7 +189,7 @@ class _BaseTreeInstance(AbstractInstanceValue):
|
|||||||
for f in class_filters:
|
for f in class_filters:
|
||||||
if isinstance(f, ClassFilter):
|
if isinstance(f, ClassFilter):
|
||||||
yield InstanceClassFilter(self, f)
|
yield InstanceClassFilter(self, f)
|
||||||
elif isinstance(f, CompiledObjectFilter):
|
elif isinstance(f, CompiledValueFilter):
|
||||||
yield CompiledInstanceClassFilter(self, f)
|
yield CompiledInstanceClassFilter(self, f)
|
||||||
else:
|
else:
|
||||||
# Propably from the metaclass.
|
# Propably from the metaclass.
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ class Slice(LazyValueWrapper):
|
|||||||
|
|
||||||
def get_safe_value(self, default=sentinel):
|
def get_safe_value(self, default=sentinel):
|
||||||
"""
|
"""
|
||||||
Imitate CompiledObject.obj behavior and return a ``builtin.slice()``
|
Imitate CompiledValue.obj behavior and return a ``builtin.slice()``
|
||||||
object.
|
object.
|
||||||
"""
|
"""
|
||||||
def get(element):
|
def get(element):
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ def test_parse_function_doc_illegal_docstr():
|
|||||||
|
|
||||||
def test_doc(inference_state):
|
def test_doc(inference_state):
|
||||||
"""
|
"""
|
||||||
Even CompiledObject docs always return empty docstrings - not None, that's
|
Even CompiledValue docs always return empty docstrings - not None, that's
|
||||||
just a Jedi API definition.
|
just a Jedi API definition.
|
||||||
"""
|
"""
|
||||||
str_ = compiled.create_simple_object(inference_state, u'')
|
str_ = compiled.create_simple_object(inference_state, u'')
|
||||||
@@ -135,7 +135,7 @@ def test_parent_context(same_process_inference_state, attribute, expected_name,
|
|||||||
dt = datetime(2000, 1, 1)
|
dt = datetime(2000, 1, 1)
|
||||||
ret_int = _return_int
|
ret_int = _return_int
|
||||||
|
|
||||||
o = compiled.CompiledObject(
|
o = compiled.CompiledValue(
|
||||||
same_process_inference_state,
|
same_process_inference_state,
|
||||||
DirectObjectAccess(same_process_inference_state, C)
|
DirectObjectAccess(same_process_inference_state, C)
|
||||||
)
|
)
|
||||||
@@ -165,7 +165,7 @@ def test_parent_context(same_process_inference_state, attribute, expected_name,
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_qualified_names(same_process_inference_state, obj, expected_names):
|
def test_qualified_names(same_process_inference_state, obj, expected_names):
|
||||||
o = compiled.CompiledObject(
|
o = compiled.CompiledValue(
|
||||||
same_process_inference_state,
|
same_process_inference_state,
|
||||||
DirectObjectAccess(same_process_inference_state, obj)
|
DirectObjectAccess(same_process_inference_state, obj)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from jedi.inference.compiled import CompiledObject
|
from jedi.inference.compiled import CompiledValue
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -15,4 +15,4 @@ def test_equals(Script, environment, source):
|
|||||||
script = Script(source)
|
script = Script(source)
|
||||||
node = script._module_node.children[0]
|
node = script._module_node.children[0]
|
||||||
first, = script._get_module_context().infer_node(node)
|
first, = script._get_module_context().infer_node(node)
|
||||||
assert isinstance(first, CompiledObject) and first.get_safe_value() is True
|
assert isinstance(first, CompiledValue) and first.get_safe_value() is True
|
||||||
|
|||||||
Reference in New Issue
Block a user