Skip to content

Commit

Permalink
[fix] regression situation where a comment after ':' would produce a …
Browse files Browse the repository at this point in the history
…parsing error
  • Loading branch information
Psycojoker committed Jan 14, 2017
1 parent 6922062 commit 98acd96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions baron/formatting_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ def group_generator(sequence):
after_space = next(iterator)
current = (current[0], current[1], current[2] if len(current) > 2 else [], [after_space])

# in case of "def a(): # comment\n pass"
# not really happy about this solution but that avoid a broken release
if current[0] == "COLON" and iterator.show_next() and iterator.show_next()[0] == "COMMENT":
comment = next(iterator)
current = (current[0], current[1], ((current[2]) if len(current) > 3 else []) + [comment])

yield current
15 changes: 15 additions & 0 deletions tests/test_formatting_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,21 @@ def test_inconsistancy_on_space_grouping():
])


def test_space_before_comment_simple():
group([
('ENDL', '\n'),
('SPACE', ' '),
('COMMENT', '# hello'),
('ENDL', '\n'),
], [
('ENDL', '\n', [], [('SPACE', ' ')]),
('COMMENT', '# hello'),
('ENDL', '\n'),
]

)


def test_space_before_comment():
group([
('ENDL', '\n'),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from baron import parse


def test_regression_trailing_comment_after_colon():
assert parse("def a(): # pouf\n pass")


def test_regression_trailing_comment_after_colon_no_space():
assert parse("def a():# pouf\n pass")

0 comments on commit 98acd96

Please sign in to comment.