Line breaking behavior for function arguments with and without trailing comma
See original GitHub issueHello 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:
- Created 7 years ago
- Reactions:21
- Comments:27 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?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: