Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED: skip comment #1254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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