forked from VimPlug/jedi
Fix value/context mixup in mixed, fixes #1479
This commit is contained in:
@@ -292,15 +292,16 @@ def _create(inference_state, access_handle, parent_context, *args):
|
|||||||
# TODO this __name__ is probably wrong.
|
# TODO this __name__ is probably wrong.
|
||||||
name = compiled_object.get_root_context().py__name__()
|
name = compiled_object.get_root_context().py__name__()
|
||||||
string_names = tuple(name.split('.'))
|
string_names = tuple(name.split('.'))
|
||||||
module_context = ModuleValue(
|
module_value = ModuleValue(
|
||||||
inference_state, module_node,
|
inference_state, module_node,
|
||||||
file_io=file_io,
|
file_io=file_io,
|
||||||
string_names=string_names,
|
string_names=string_names,
|
||||||
code_lines=code_lines,
|
code_lines=code_lines,
|
||||||
is_package=compiled_object.is_package(),
|
is_package=compiled_object.is_package(),
|
||||||
).as_context()
|
)
|
||||||
if name is not None:
|
if name is not None:
|
||||||
inference_state.module_cache.add(string_names, ValueSet([module_context]))
|
inference_state.module_cache.add(string_names, ValueSet([module_value]))
|
||||||
|
module_context = module_value.as_context()
|
||||||
else:
|
else:
|
||||||
if parent_context.tree_node.get_root_node() != module_node:
|
if parent_context.tree_node.get_root_node() != module_node:
|
||||||
# This happens e.g. when __module__ is wrong, or when using
|
# This happens e.g. when __module__ is wrong, or when using
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ if sys.version_info > (3, 5):
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
|
from jedi.inference.value import ModuleValue
|
||||||
|
|
||||||
|
|
||||||
def interpreter(code, namespace, *args, **kwargs):
|
def interpreter(code, namespace, *args, **kwargs):
|
||||||
@@ -40,3 +41,13 @@ def test_generics():
|
|||||||
|
|
||||||
s = StackWrapper()
|
s = StackWrapper()
|
||||||
print(interpreter('s.stack.pop().', locals()).complete())
|
print(interpreter('s.stack.pop().', locals()).complete())
|
||||||
|
|
||||||
|
|
||||||
|
def test_mixed_module_cache():
|
||||||
|
"""Caused by #1479"""
|
||||||
|
interpreter = jedi.Interpreter('jedi', [{'jedi': jedi}])
|
||||||
|
d, = interpreter.infer()
|
||||||
|
assert d.name == 'jedi'
|
||||||
|
inference_state = interpreter._inference_state
|
||||||
|
jedi_module, = inference_state.module_cache.get(('jedi',))
|
||||||
|
assert isinstance(jedi_module, ModuleValue)
|
||||||
|
|||||||
Reference in New Issue
Block a user