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.

Please manage commas

See original GitHub issue

I expect yapf, as a style-normalizer, to handle the trailing comma issue for me. Some writers put it always, others never, and yapf should make the code look the same regardless of who wrote it.

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)

Desired output: (in all three cases)

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,
)

Actual output: (note trailing comma missing in second case)

$ yapf --style facebook ./demo.py
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
)

In this case I have to hunt down missing trailing commas and fix them by hand, which is very similar to the problem yapf was made to solve – often in code reviews you’ll see junior devs told “trailing commas are nice”.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:47
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
asottilecommented, Oct 15, 2019

for those looking for a battle-tested tool which modifies the token stream to add commas (with options for different target python versions) I’ve written add-trailing-comma

3reactions
bwendlingcommented, Oct 3, 2016

In general, I’m against modifying the token stream. I did it before and it’s fraught with problems. If someone wants to submit a patch, I’ll consider it. But it’ll have to be contained behind a style knob and come with a bevy of tests…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comma Rules for Clear Writing (with Examples) - HubSpot Blog
Use a comma between two coordinate adjectives that describe the same noun. Use a comma to highlight additional, non-essential information about ...
Read more >
Should I use a comma before or after “please” in a sentence?
If please is at the beginning of a sentence, you can choose whether or not to put a comma after it. It depends...
Read more >
In what cases should I use a comma after "please"?
A comma is almost always required before "please" at the end of the sentence. Whether to use a comma or not depends on...
Read more >
A Word, Please: When to use commas, when not to use them
It's an example of a comma situation that confounds many people yet is surprisingly easy to handle. Did you notice that, in our...
Read more >
Commas (Eight Basic Uses) - Indiana University East
Rule: Use a comma after an introductory clause or phrase. ... Please send the letter to Greg Carvin at 708 Spring Street, Washington,...
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