Skip to content

Commit

Permalink
(fix) SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED: skip comment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Dec 10, 2024
1 parent bb83461 commit 849ed5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ def SurroundedByParens(token):
if opening and opening.previous_token and opening.previous_token.is_name:
if previous.value in '(,':
if opening.matching_bracket.previous_token.value == ',':
if current.is_comment:
# Don't require splitting before a comment, since it may be
# related to the current line.
return False
return True

if (style.Get('SPLIT_BEFORE_NAMED_ASSIGNS') and not current.is_comment and
Expand Down
10 changes: 10 additions & 0 deletions yapftests/reformatter_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,10 @@ def _pack_results_for_constraint_or(cls, combination, constraints):

def testSplittingArgumentsTerminatedByComma(self):
unformatted_code = textwrap.dedent("""\
class Class( # comment
object,):
pass
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3)
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3,)
Expand All @@ -2351,6 +2355,12 @@ def testSplittingArgumentsTerminatedByComma(self):
r =f0 (a=1,)
""") # noqa
expected_formatted_code = textwrap.dedent("""\
class Class( # comment
object,
):
pass
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3)
function_name(
Expand Down

0 comments on commit 849ed5d

Please sign in to comment.