diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 699adb89..54e3f587 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -230,7 +230,14 @@ class Script(object): continue names = s.get_defined_names(on_import_stmt=True) else: - names = s.get_defined_names() + try: + sng = s.scope_names_generator + except AttributeError: + names = s.get_defined_names() + else: + names = [] + for _, new_names in sng(): + names += new_names for c in names: completions.append((c, s)) diff --git a/test/completion/imports.py b/test/completion/imports.py index 0cadc88a..2aefb373 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -19,8 +19,6 @@ def scope_basic(): #? str() import_tree.a - #? [] - import_tree.mod1 def scope_pkg(): import import_tree.mod1 @@ -64,7 +62,11 @@ def scope_nested2(): import_tree.mod1 #? ['pkg'] import_tree.pkg - #? [] + + # With the latest changes this completion also works, because submodules + # are always included (some nested import structures lead to this, + # typically). + #? ['rename1'] import_tree.rename1 def from_names():