From 750b8af37bc7d6ae5f04933965e39c0e101ca06c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 31 Dec 2018 01:25:11 +0100 Subject: [PATCH] Fix diff parser get_last_line calculation --- parso/python/diff.py | 3 +++ test/test_diff_parser.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/parso/python/diff.py b/parso/python/diff.py index 8a05565..57fbbb0 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -447,6 +447,9 @@ class _NodesTreeNode(object): if suffix and not suffix.endswith('\n'): # This is the end of a file (that doesn't end with a newline). line += 1 + + if self._node_children: + return max(line, self._node_children[-1].get_last_line(suffix)) return line diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index dd5366f..fa4eaf2 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -579,3 +579,29 @@ def test_add_error_indentation(differ): code = 'if x:\n 1\n' differ.initialize(code) differ.parse(code + ' 2\n', parsers=1, copies=0, expect_error_leaves=True) + + +def test_differing_docstrings(differ): + code1 = dedent('''\ + def foobar(x, y): + 1 + return x + + def bazbiz(): + foobar() + lala + ''') + + code2 = dedent('''\ + def foobar(x, y): + 2 + return x + y + + def bazbiz(): + z = foobar() + lala + ''') + + differ.initialize(code1) + differ.parse(code2, parsers=3, copies=1) + differ.parse(code1, parsers=3, copies=1)