diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 6972dcb3..93700532 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -72,14 +72,14 @@ class CachedFastParser(type): class ParserNode(object): def __init__(self, parser, code, parent=None): self.parent = parent - self.code = code - self.hash = hash(code) self.children = [] # must be created before new things are added to it. - self.save_contents(parser) + self.save_contents(parser, code) - def save_contents(self, parser): + def save_contents(self, parser, code): + self.code = code + self.hash = hash(code) self.parser = parser try: @@ -325,7 +325,7 @@ class FastParser(use_metaclass(CachedFastParser)): if self.current_node is None: self.current_node = ParserNode(new, '') else: - self.current_node.save_contents(new) + self.current_node.save_contents(new, '') self.parsers.append(new) is_first = False @@ -333,7 +333,7 @@ class FastParser(use_metaclass(CachedFastParser)): if self.current_node is None: self.current_node = ParserNode(p, code_part_actually_used) else: - self.current_node.save_contents(p) + self.current_node.save_contents(p, code_part_actually_used) else: if node is None: self.current_node = \ diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 28f9713c..e7883cfa 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -59,18 +59,22 @@ def test_carriage_return_splitting(): def test_change_and_undo(): - cache.parser_cache.pop(None, None) def fp(src): p = FastParser(u(src)) cache.save_parser(None, None, p, pickling=False) - # TODO Don't just take the first line, the whole thing should be the same. - # Need to refactor the parser first, though. - print(repr(p.module.get_code())) - first_line = p.module.get_code().splitlines()[0] - assert first_line == src + # TODO Don't change get_code, the whole thing should be the same. + # -> Need to refactor the parser first, though. + assert src == p.module.get_code()[:-1] + cache.parser_cache.pop(None, None) + func_before = 'def func():\n pass\n' + fp(func_before + 'a') + fp(func_before + 'b') + fp(func_before + 'a') + + cache.parser_cache.pop(None, None) fp('a') fp('b') fp('a')