diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 4363cc05..a743f813 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -424,14 +424,12 @@ class FastParser(use_metaclass(CachedFastParser)): """ Side effect: Alters the list of nodes. """ - indent = len(source) - len(source.lstrip('\t ')) - self.current_node = self.current_node.parent_until_indent(indent) - h = hash(source) for index, node in enumerate(nodes): if node.hash == h and node.source == source: node.reset_node() nodes.remove(node) + parser_code = source break else: tokenizer = FastTokenizer(parser_code) @@ -444,6 +442,9 @@ class FastParser(use_metaclass(CachedFastParser)): node = ParserNode(self.module, p, code_part_actually_used) + indent = len(parser_code) - len(parser_code.lstrip('\t ')) + self.current_node = self.current_node.parent_until_indent(indent) + self.current_node.add_node(node, line_offset) return node diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index a80a0984..56a783f8 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -447,11 +447,14 @@ def test_decorator_string_issue(): """ Test case from #589 """ - s = jedi.Script(dedent('''\ + source = dedent('''\ """ @""" def bla(): pass - bla.''')) + bla.''') + + s = jedi.Script(source) assert s.completions() + assert s._parser.module().get_code() == source