google / google/yapf

Add knob for forcing a comma on last element of multi-line collection literals

Open
#443 3 comments 32 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

I think it is valuable to require, in a coding style, that multi-line collection literals have a comma after the trailing entry. This is beneficial since it means that future additions to the collection require only changing the lines that were added, without changing the previous last entry. This makes the output of tools like `git blame` more useful.

Furthermore, it would be nice if `yapf` could enforce this style, so it wouldn't be left to code reviews.

I understand this may conflict with the use of comma as a signal to split or not.

Example:
```
a = {
"hi": 1,
"bye": 2,
"why": 3,
"try": 4,
"fill the sky": 5,
"what do you use to ply": 6,
"i'm a gruntled guy": 7,
"she's a small fish to fry": 8
}
```
would be transformed to
```
a = {
"hi": 1,
"bye": 2,
"why": 3,
"try": 4,
"fill the sky": 5,
"what do you use to ply": 6,
"i'm a gruntled guy": 7,
"she's a small fish to fry": 8,
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.