From 81174741a4b4f78e8b5d6bc41b482df84cfc8ff4 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 2 Nov 2014 17:40:45 +0100 Subject: [PATCH] After error recovery, names need to be removed from the used_names list, because they are not actually defined in the current AST. --- jedi/parser/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index f16ff9e0..4fcdad3a 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -112,7 +112,7 @@ class Parser(object): if symbol in (grammar.symbol2number['simple_stmt'], grammar.symbol2number['stmt']): index = i - stack[index:] = [] + self._stack_removal(stack, index) else: # For now just discard everything that is not a suite or # file_input, if we detect an error. @@ -124,10 +124,26 @@ class Parser(object): grammar.symbol2number['suite']): index = i break - stack[index + 1:] = [] + self._stack_removal(stack, index + 1) # No success finding a transition #raise ParseError("bad input", type, value, context) + def _stack_removal(self, stack, start_index): + def clear_names(children): + for c in children: + try: + clear_names(c.children) + except AttributeError: + if isinstance(c, pr.Name): + self.scope_names_stack[-1][c.value].remove(c) + self.used_names[c.value].remove(c) + + for dfa, state, node in stack[start_index:]: + clear_names(children=node[3]) + + stack[start_index:] = [] + + def __init__old__(self, source, module_path=None, no_docstr=False, tokenizer=None, top_module=None): self.no_docstr = no_docstr