question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line breaking behavior for function arguments with and without trailing comma

See original GitHub issue

Hello and thanks for YAPF. It’s been working nicely for us, except for the formatting of long function arguments. Take a look at the example below. If a trailing comma is present, we would like to keep the them in individual lines. Without trailing comma, an option to break right after the opening parenthesis would be nice. This is PEP8 conform (as is the the YAPF output) and plays more nicely with with long function names.

Desired format:

a_very_long_function_name(
    long_argument_name_1=1,
    long_argument_name_2=2,
    long_argument_name_3=3,
    long_argument_name_4=4,
)

a_very_long_function_name(
    long_argument_name_1=1, long_argument_name_2=2,
    long_argument_name_3=3, long_argument_name_4=4)

YAPF output:

a_very_long_function_name(long_argument_name_1=1,
                          long_argument_name_2=2,
                          long_argument_name_3=3,
                          long_argument_name_4=4, )

a_very_long_function_name(long_argument_name_1=1,
                          long_argument_name_2=2,
                          long_argument_name_3=3,
                          long_argument_name_4=4)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:21
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

12reactions
malcolmgreavescommented, Apr 28, 2018

Hello! I have been evaluating bringing in yapf to a few projects. I found this thread and realized that the this issue applies to my current adoption. Has there been any resolutions, updates, or work-arounds discovered?

9reactions
Chaostecommented, May 23, 2016

Maybe there was a misunderstanding what behavior we would like a trailing comma to cause. If there is a trailing comma, each argument and the closing parenthesis should have their own lines to easily edit individual arguments (regardless of line length and DEDENT_CLOSING_BRACKETS knob). Some examples to illustrate:

function_name(argument_name_1=1, argument_name_2=2, argument_name_3=3)

# Break even though this would fit into a single line.
function_name(
    argument_name_1=1,
    argument_name_2=2,
    argument_name_3=3,
)

a_very_long_function_name(
    long_argument_name_1=1, long_argument_name_2=2, long_argument_name_3=3,
    long_argument_name_4=4)

a_very_long_function_name(
    long_argument_name_1=1,
    long_argument_name_2=2,
    long_argument_name_3=3,
    long_argument_name_4=4,
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore argument missing error in ellipsis function
The following piece of code produces Error: argument is missing, with no default because of the trailing comma ...
Read more >
The Black code style - Black 22.12.0 documentation
Black will add trailing commas to expressions that are split by comma where each element is on its own line. This includes function...
Read more >
prefer-trailing-comma - Dart Code Metrics
Check for trailing comma for arguments, parameters, enum values and collections. By default warns in cases when items aren't on a single line....
Read more >
Clang-Format Style Options — Clang 16.0.0git documentation
For example, to align across empty lines and not across comments, either of these work. ... The function definition return type breaking style...
Read more >
Comma omission and comma deletion - open-std.org
1. Delete any commas if there are no variable arguments ... This is a minimal, unsurprising extension. However, it suffers from the major...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found