forked from VimPlug/jedi
Fix more issues with where contexts are used and where values are used
This commit is contained in:
@@ -21,6 +21,7 @@ from jedi.inference.compiled.access import compiled_objects_cache, \
|
||||
ALLOWED_GETITEM_TYPES, get_api_type
|
||||
from jedi.inference.compiled.value import create_cached_compiled_object
|
||||
from jedi.inference.gradual.conversion import to_stub
|
||||
from jedi.inference.context import CompiledContext
|
||||
|
||||
_sentinel = object()
|
||||
|
||||
@@ -70,6 +71,9 @@ class MixedObject(ValueWrapper):
|
||||
return self.compiled_object.py__simple_getitem__(index)
|
||||
raise SimpleGetItemNotFound
|
||||
|
||||
def _as_context(self):
|
||||
return MixedContext(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (
|
||||
type(self).__name__,
|
||||
@@ -77,6 +81,12 @@ class MixedObject(ValueWrapper):
|
||||
)
|
||||
|
||||
|
||||
class MixedContext(CompiledContext):
|
||||
@property
|
||||
def compiled_object(self):
|
||||
return self._value.compiled_object
|
||||
|
||||
|
||||
class MixedName(compiled.CompiledName):
|
||||
"""
|
||||
The ``CompiledName._compiled_object`` is our MixedObject.
|
||||
@@ -102,7 +112,7 @@ class MixedName(compiled.CompiledName):
|
||||
else:
|
||||
parent_context = parent_value.as_context()
|
||||
|
||||
if parent_context is None or isinstance(parent_context, MixedObject):
|
||||
if parent_context is None or isinstance(parent_context, MixedContext):
|
||||
return _create(self._inference_state, access, parent_context=parent_context)
|
||||
else:
|
||||
return ValueSet({
|
||||
@@ -244,7 +254,8 @@ def _create(inference_state, access_handle, parent_context, *args):
|
||||
compiled_object = create_cached_compiled_object(
|
||||
inference_state,
|
||||
access_handle,
|
||||
parent_context=parent_context and parent_context.compiled_object
|
||||
parent_context=None if parent_context is None
|
||||
else parent_context.compiled_object.as_context() # noqa
|
||||
)
|
||||
|
||||
# TODO accessing this is bad, but it probably doesn't matter that much,
|
||||
|
||||
@@ -530,13 +530,18 @@ def _normalize_create_args(func):
|
||||
|
||||
|
||||
def create_from_access_path(inference_state, access_path):
|
||||
parent_context = None
|
||||
value = None
|
||||
for name, access in access_path.accesses:
|
||||
parent_context = create_cached_compiled_object(inference_state, access, parent_context)
|
||||
return parent_context
|
||||
value = create_cached_compiled_object(
|
||||
inference_state,
|
||||
access,
|
||||
parent_context=None if value is None else value.as_context()
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
@_normalize_create_args
|
||||
@inference_state_function_cache()
|
||||
def create_cached_compiled_object(inference_state, access_handle, parent_context):
|
||||
assert not isinstance(parent_context, CompiledObject)
|
||||
return CompiledObject(inference_state, access_handle, parent_context)
|
||||
|
||||
Reference in New Issue
Block a user