mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 21:04:29 +08:00
Ignore ERROR_DEDENT in graph validation
This commit is contained in:
@@ -31,10 +31,10 @@ def _assert_valid_graph(node):
|
|||||||
|
|
||||||
# Ignore INDENT is necessary, because indent/dedent tokens don't
|
# Ignore INDENT is necessary, because indent/dedent tokens don't
|
||||||
# contain value/prefix and are just around, because of the tokenizer.
|
# 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
|
return
|
||||||
while previous_leaf and previous_leaf.type == 'error_leaf' \
|
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, \
|
assert previous_leaf.end_pos <= node.start_pos, \
|
||||||
(previous_leaf, node)
|
(previous_leaf, node)
|
||||||
previous_leaf = previous_leaf.get_previous_leaf()
|
previous_leaf = previous_leaf.get_previous_leaf()
|
||||||
|
|||||||
@@ -640,3 +640,28 @@ def test_one_call_in_function_change(differ):
|
|||||||
differ.initialize(code1)
|
differ.initialize(code1)
|
||||||
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
|
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
|
||||||
differ.parse(code1, parsers=2, copies=1)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user