From 6b535c0503a3de751613df61ed369be0c10ac689 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 30 Jan 2018 01:19:55 +0100 Subject: [PATCH] Fix the last remaining issues with ahead of time annotations, see #982 --- jedi/evaluate/syntax_tree.py | 16 ++++++++-------- test/completion/pep0484_aheadoftime.py | 8 -------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index f41a01fb..62a004d6 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -443,16 +443,16 @@ def _remove_statements(evaluator, context, stmt, name): def tree_name_to_contexts(evaluator, context, tree_name): context_set = ContextSet() - module = context.get_root_context().tree_node - names = module.get_used_names().get(tree_name.value) - for name in names: - expr_stmt = name.parent + module_node = context.get_root_context().tree_node + if module_node is not None: + names = module_node.get_used_names().get(tree_name.value, []) + for name in names: + expr_stmt = name.parent - correct_scope = parser_utils.get_parent_scope(name) == context.tree_node + correct_scope = parser_utils.get_parent_scope(name) == context.tree_node - if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign" and correct_scope: - print("found node in correct scope!", expr_stmt.children[1].children[1]) - context_set |= _evaluate_for_annotation(context, expr_stmt.children[1].children[1]) + if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign" and correct_scope: + context_set |= _evaluate_for_annotation(context, expr_stmt.children[1].children[1]) if context_set: return context_set diff --git a/test/completion/pep0484_aheadoftime.py b/test/completion/pep0484_aheadoftime.py index 3710e824..fb31a931 100644 --- a/test/completion/pep0484_aheadoftime.py +++ b/test/completion/pep0484_aheadoftime.py @@ -24,11 +24,3 @@ char: str for char in test_string: #? str() char - - -import numpy -somearrays = [numpy.ones((10, 10)), numpy.eye(10), 2, 2.3] -array : numpy.ndarray -for array in somearrays[0:2]: - #? numpy.ndarray() - array