Fix the last remaining issues with ahead of time annotations, see #982

This commit is contained in:
Dave Halter
2018-01-30 01:19:55 +01:00
parent 24561759f6
commit 6b535c0503
2 changed files with 8 additions and 16 deletions

View File

@@ -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

View File

@@ -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