Skip to content

Commit ecb922c

Browse files
committed
Fix a few issues around duplicated import paths, fixes #2033
1 parent 41e9e95 commit ecb922c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

jedi/api/completion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,14 @@ def search_in_module(inference_state, module_context, names, wanted_names,
683683
def extract_imported_names(node):
684684
imported_names = []
685685

686-
if node.type in ['import_as_names', 'dotted_as_names', 'import_as_name']:
686+
if node.type in ['import_as_names', 'dotted_as_names', 'dotted_as_name', 'import_as_name']:
687687
for index, child in enumerate(node.children):
688688
if child.type == 'name':
689-
if (index > 0 and node.children[index - 1].type == "keyword"
689+
if (index > 1 and node.children[index - 1].type == "keyword"
690690
and node.children[index - 1].value == "as"):
691691
continue
692692
imported_names.append(child.value)
693-
elif child.type == 'import_as_name':
693+
elif child.type in ('import_as_name', 'dotted_as_name'):
694694
imported_names.extend(extract_imported_names(child))
695695

696696
return imported_names

test/test_inference/test_imports.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,14 @@ def import_names(*args, **kwargs):
318318
s = 'from os import path, p'
319319
assert 'path' not in import_names(s)
320320
assert 'path' in import_names(s, column=len(s) - 3)
321+
assert 'path' in import_names("from import path")
322+
assert 'path' in import_names("from import chdir, path")
321323

322-
s = 'import path as pp, p'
323-
assert 'path' not in import_names(s)
324+
s = 'import math as mm, m'
325+
assert 'math' not in import_names(s)
326+
327+
s = 'import math as os, o'
328+
assert 'os' in import_names(s)
324329

325330
s = 'from os import path as pp, p'
326331
assert 'path' not in import_names(s)

0 commit comments

Comments
 (0)