diff --git a/jedi/api/interpreter.py b/jedi/api/interpreter.py index 25f21f4e..9359cf1c 100644 --- a/jedi/api/interpreter.py +++ b/jedi/api/interpreter.py @@ -18,13 +18,17 @@ from jedi.evaluate import iterable from jedi.evaluate.compiled import mixed -def add_namespaces_to_parser(evaluator, namespaces, parser_module): - for namespace in namespaces: - for key, value in namespace.items(): +def add_namespaces_to_parser(evaluator, namespace_dicts, parser_module): + for dct in namespace_dicts: + namespace = compiled.CompiledObject(evaluator, type('namespace', (), dct)) + + for key, value in dct.items(): # Name lookups in an ast tree work by checking names_dict. # Therefore we just add fake names to that and we're done. arr = parser_module.names_dict.setdefault(key, []) - arr.append(LazyName(evaluator, parser_module, key, value)) + name = mixed.MixedName(evaluator, namespace, key) + arr.append(name) + #arr.append(LazyName(evaluator, parser_module, key, value)) class LazyName(helpers.FakeName): diff --git a/jedi/evaluate/compiled/mixed.py b/jedi/evaluate/compiled/mixed.py index 2aee1cbe..c47b3cc3 100644 --- a/jedi/evaluate/compiled/mixed.py +++ b/jedi/evaluate/compiled/mixed.py @@ -56,7 +56,15 @@ class MixedName(compiled.CompiledName): @parent.setter def parent(self, value): - pass # Just ignore this, FakeName tries to overwrite the parent attribute. + pass # Just ignore this, Name tries to overwrite the parent attribute. + + @property + def start_pos(self): + if isinstance(self.parent, MixedObject): + return self.parent.node_name.start_pos + + # This means a start_pos that doesn't exist (compiled objects). + return (0, 0) class LazyMixedNamesDict(compiled.LazyNamesDict): diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 957bc247..7b744d22 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -47,7 +47,7 @@ def test_nested_resolve(): cls = get_completion('X', locals()) func = get_completion('X.x', locals()) - assert func.start_pos == (func.start_pos[0] + 1, 8) + assert func.start_pos == (cls.start_pos[0] + 1, 12) def test_side_effect_completion():