From 5fab42916305e3b0a67551aadeeb74d312526d58 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 22 May 2017 15:37:26 -0400 Subject: [PATCH] Fix a diff parser issue with a test as well. --- parso/grammar.py | 3 +-- test/test_diff_parser.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/parso/grammar.py b/parso/grammar.py index 71112f3..dd65a1b 100644 --- a/parso/grammar.py +++ b/parso/grammar.py @@ -76,8 +76,7 @@ class Grammar(object): cache_path=cache_path) return module_node - # TODO I think it's wrong that we have self here. - new_node = DiffParser(self, module_node).update( + new_node = DiffParser(self._pgen_grammar, module_node).update( old_lines=old_lines, new_lines=lines ) diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index bff0979..f279f6c 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -10,6 +10,15 @@ from parso.python.diff import DiffParser from parso.python import parse +def test_simple(): + """ + The diff parser reuses modules. So check for that. + """ + grammar = load_python_grammar() + module_a = grammar.parse('a', diff_cache=True) + assert grammar.parse('b', diff_cache=True) == module_a + + def _check_error_leaves_nodes(node): if node.type in ('error_leaf', 'error_node'): return True