From 43651ef219299ae32a45215d6d3a067e029f61b6 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 24 Mar 2020 22:27:04 +0100 Subject: [PATCH] Diff parser: Make sure dedent start pos are matching --- parso/python/diff.py | 10 ++++++---- test/test_diff_parser.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/parso/python/diff.py b/parso/python/diff.py index e69d2ed..8787f27 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -456,7 +456,7 @@ class _NodesTreeNode(object): if add_error_leaf == 'INDENT': pos = children_part[0].start_pos else: - pos = children[-1].end_pos + pos = children_part[0].start_pos[0], 0 children.append(PythonErrorLeaf(add_error_leaf, '', pos)) children += children_part self.tree_node.children = children @@ -547,11 +547,13 @@ class _NodesTree(object): # having the right indentation. break elif tree_node.type == 'file_input': - if indentation > 0 and indentation != node.get_latest_indentation(): - if previous_node is None: + latest_indentation = node.get_latest_indentation() + if indentation > 0 and indentation != latest_indentation: + if previous_node is None and indentation > latest_indentation: add_error_leaf = 'INDENT' else: - node = previous_node + if previous_node is not None: + node = previous_node add_error_leaf = 'ERROR_DEDENT' break previous_node = node diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index e61fc6a..fbc545e 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -47,7 +47,7 @@ def _assert_nodes_are_equal(node1, node2): assert node1.value == node2.value #assert node1.type == node2.type assert node1.prefix == node2.prefix - #assert node1.start_pos == node2.start_pos + assert node1.start_pos == node2.start_pos return else: try: