Skip to content

Commit 849ed5d

Browse files
committed
(fix) SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED: skip comment
1 parent bb83461 commit 849ed5d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

yapf/yapflib/format_decision_state.py

+4
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ def SurroundedByParens(token):
390390
if opening and opening.previous_token and opening.previous_token.is_name:
391391
if previous.value in '(,':
392392
if opening.matching_bracket.previous_token.value == ',':
393+
if current.is_comment:
394+
# Don't require splitting before a comment, since it may be
395+
# related to the current line.
396+
return False
393397
return True
394398

395399
if (style.Get('SPLIT_BEFORE_NAMED_ASSIGNS') and not current.is_comment and

yapftests/reformatter_basic_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,10 @@ def _pack_results_for_constraint_or(cls, combination, constraints):
23362336

23372337
def testSplittingArgumentsTerminatedByComma(self):
23382338
unformatted_code = textwrap.dedent("""\
2339+
class Class( # comment
2340+
object,):
2341+
pass
2342+
23392343
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3)
23402344
23412345
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3,)
@@ -2351,6 +2355,12 @@ def testSplittingArgumentsTerminatedByComma(self):
23512355
r =f0 (a=1,)
23522356
""") # noqa
23532357
expected_formatted_code = textwrap.dedent("""\
2358+
class Class( # comment
2359+
object,
2360+
):
2361+
pass
2362+
2363+
23542364
function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3)
23552365
23562366
function_name(

0 commit comments

Comments
 (0)