From c2eacdb81cfd6bbc1c8dfb82abd9300be327f8e1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 20 May 2018 19:13:08 +0200 Subject: [PATCH] The diff parser was slighly off with prefixes, fixes #1121 --- parso/python/diff.py | 5 +++-- test/test_diff_parser.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/parso/python/diff.py b/parso/python/diff.py index 96c6e5f..f8b73c7 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -490,6 +490,9 @@ class _NodesStack(object): new_tos = tos for node in nodes: + if node.start_pos[0] > until_line: + break + if node.type == 'endmarker': # We basically removed the endmarker, but we are not allowed to # remove the newline at the end of the line, otherwise it's @@ -501,8 +504,6 @@ class _NodesStack(object): # Endmarkers just distort all the checks below. Remove them. break - if node.start_pos[0] > until_line: - break # TODO this check might take a bit of time for large files. We # might want to change this to do more intelligent guessing or # binary search. diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index 83ff8ba..ec752ca 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -502,3 +502,8 @@ def test_endmarker_newline(differ): differ.initialize(code1) differ.parse(code2, parsers=2, copies=2, expect_error_leaves=True) + + +def test_newlines_at_end(differ): + differ.initialize('a\n\n') + differ.parse('a\n', copies=1)