Skip to content
Snippets Groups Projects
Commit bca4d429 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[fix] unindented comment between if/elif/else was breaking parsing

parent 585e6499
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -83,7 +83,7 @@ def mark_indentation_generator(sequence):
# if we were in an indented situation and that the next line has a lower indentation
if indentations and current[0] == "ENDL":
the_indentation_level_changed = get_space(current) is None or get_space(current) != indentations[-1]
if the_indentation_level_changed and iterator.show_next()[0] != "ENDL":
if the_indentation_level_changed and iterator.show_next()[0] not in ("ENDL", "COMMENT"):
new_indent = get_space(current) if len(current) == 4 else ""
yield current
 
Loading
Loading
Loading
Loading
@@ -337,3 +337,41 @@ def test_tab_and_spaces_because_some_people_are_horrible():
('PASS', 'pass'),
('DEDENT', ''),
])
def test_comment_in_middle_of_ifelseblock():
check([
('ENDL', '\n'),
('IF', 'if', [], [('SPACE', ' ')]),
('NAME', 'a'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('PASS', 'pass'),
('ENDL', '\n'),
('COMMENT', '# comment'),
('ENDL', '\n'),
('ELSE', 'else'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('PASS', 'pass'),
('ENDL', '\n'),
], [
('ENDL', '\n'),
('IF', 'if', [], [('SPACE', ' ')]),
('NAME', 'a'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('INDENT', ''),
('PASS', 'pass'),
('ENDL', '\n'),
('COMMENT', '# comment'),
('ENDL', '\n'),
('DEDENT', ''),
('ELSE', 'else'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('INDENT', ''),
('PASS', 'pass'),
('ENDL', '\n'),
('DEDENT', ''),
])
Loading
Loading
@@ -17,3 +17,8 @@ def test_regression_trailing_comment_after_colon_dump():
def test_regression_trailing_comment_after_colon_no_space_dump():
code = "def a():# pouf\n pass\n"
assert dumps(parse(code)) == code
def test_comment_in_middle_of_ifelseblock():
code = 'if a:\n pass\n# comment\nelse:\n pass\n'
assert dumps(parse(code)) == code
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment