Ignore ERROR_DEDENT in graph validation

This commit is contained in:
Dave Halter
2019-01-02 11:31:09 +01:00
parent e0d0e57bd0
commit a9f58b7c45
2 changed files with 27 additions and 2 deletions

View File

@@ -31,10 +31,10 @@ def _assert_valid_graph(node):
# Ignore INDENT is necessary, because indent/dedent tokens don't
# contain value/prefix and are just around, because of the tokenizer.
if node.type == 'error_leaf' and node.token_type == 'INDENT':
if node.type == 'error_leaf' and node.token_type in ('INDENT', 'ERROR_DEDENT'):
return
while previous_leaf and previous_leaf.type == 'error_leaf' \
and previous_leaf.token_type == 'INDENT':
and previous_leaf.token_type in ('INDENT', 'ERROR_DEDENT'):
assert previous_leaf.end_pos <= node.start_pos, \
(previous_leaf, node)
previous_leaf = previous_leaf.get_previous_leaf()

View File

@@ -640,3 +640,28 @@ def test_one_call_in_function_change(differ):
differ.initialize(code1)
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
differ.parse(code1, parsers=2, copies=1)
def test_function_deletion(differ):
code1 = dedent('''\
class C(list):
def f(self):
def iterate():
for x in b:
break
return list(iterate())
''')
code2 = dedent('''\
class C():
def f(self):
for x in b:
break
return list(iterate())
''')
differ.initialize(code1)
differ.parse(code2, parsers=1, copies=0, expect_error_leaves=True)
differ.parse(code1, parsers=1, copies=0)