forked from VimPlug/jedi
Fix a few issues around duplicated import paths, fixes #2033
This commit is contained in:
@@ -683,14 +683,14 @@ def search_in_module(inference_state, module_context, names, wanted_names,
|
||||
def extract_imported_names(node):
|
||||
imported_names = []
|
||||
|
||||
if node.type in ['import_as_names', 'dotted_as_names', 'import_as_name']:
|
||||
if node.type in ['import_as_names', 'dotted_as_names', 'dotted_as_name', 'import_as_name']:
|
||||
for index, child in enumerate(node.children):
|
||||
if child.type == 'name':
|
||||
if (index > 0 and node.children[index - 1].type == "keyword"
|
||||
if (index > 1 and node.children[index - 1].type == "keyword"
|
||||
and node.children[index - 1].value == "as"):
|
||||
continue
|
||||
imported_names.append(child.value)
|
||||
elif child.type == 'import_as_name':
|
||||
elif child.type in ('import_as_name', 'dotted_as_name'):
|
||||
imported_names.extend(extract_imported_names(child))
|
||||
|
||||
return imported_names
|
||||
|
||||
@@ -318,9 +318,14 @@ def test_duplicated_import(Script):
|
||||
s = 'from os import path, p'
|
||||
assert 'path' not in import_names(s)
|
||||
assert 'path' in import_names(s, column=len(s) - 3)
|
||||
assert 'path' in import_names("from import path")
|
||||
assert 'path' in import_names("from import chdir, path")
|
||||
|
||||
s = 'import path as pp, p'
|
||||
assert 'path' not in import_names(s)
|
||||
s = 'import math as mm, m'
|
||||
assert 'math' not in import_names(s)
|
||||
|
||||
s = 'import math as os, o'
|
||||
assert 'os' in import_names(s)
|
||||
|
||||
s = 'from os import path as pp, p'
|
||||
assert 'path' not in import_names(s)
|
||||
|
||||
Reference in New Issue
Block a user