1
0
forked from VimPlug/jedi

Fix on_import tests.

This commit is contained in:
Dave Halter
2014-11-26 03:07:41 +01:00
parent 1326a2137d
commit f24a3bf997
4 changed files with 30 additions and 12 deletions

View File

@@ -36,24 +36,30 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
def check_error_statements(evaluator, module, pos):
for error_statement in module.error_statement_stacks:
if error_statement.first_type in ('import_from' or 'import_name') \
if error_statement.first_type in ('import_from', 'import_name') \
and error_statement.first_pos < pos <= error_statement.next_start_pos:
return importer_from_error_statement(evaluator, module, error_statement, pos)
return None
def importer_from_error_statement(evaluator, module, error_statement, pos):
def check_dotted(children):
for name in children[::2]:
if name.end_pos < pos:
yield name
names = []
level = 0
for typ, nodes in error_statement.stack:
if typ == 'dotted_name':
names += nodes[::2]
names += check_dotted(nodes)
elif typ == 'import_from':
for node in nodes:
if isinstance(node, pt.Node) and node.type == 'dotted_name':
names += node.children[::2]
print(typ, nodes)
print('x', names)
names += check_dotted(node.children[::2])
elif node in ('.', '...'):
level += len(node.value)
elif isinstance(node, pt.Name) and node.end_pos < pos:
names.append(node)
return imports.get_importer(evaluator, names, module, level)