-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Different style depending on trailing comma #1643
Comments
Just two more thoughts about tihs:
|
This feature has been there since 19.10b0 and documented: https://black.readthedocs.io/en/stable/the_black_code_style.html#the-magic-trailing-comma It just used to work rather unpredictably which was fixed by 20.8b0. The rationale is to decrease diff size. If you want to prepare your code for a growing list, dictionary, etc., you use a trailing comma and it keeps the bracket pair exploded with one item per line. |
@ambv In this section of the style guide it states something different https://black.readthedocs.io/en/stable/the_black_code_style.html#trailing-commas
It seems like black 20 is now very explicitly NOT removing unnecessary trailing commas, and instead forces them onto multiple lines (when unnecessary) and it is on the user to adjust from black 19 and remove these trailing commas to keep on a single line? Additionally, the line wrap section of the doc https://black.readthedocs.io/en/stable/the_black_code_style.html#how-black-wraps-lines I'd like to request this get reopened based on the discrepancy with this documentation. |
Hey @tstraley you appear to be a bit misinformed. You are reading an old version of the documentation which is outdated/incorrect in a few ways. If you look at the latest version (i.e. on the master branch), those now incorrect paragraphs been replaced with a paragraph linking to the also new section about the "magic trailing comma" feature edit: the new section detailing the "magic trailing comma" feature is present in the stable version of the docs, while the incorrect paragraphs were removed after the new stable docs were released |
@ichard26 thanks for pointing me to the master docs yet to be published. Is there a change to fix the wrap-lines section that suggests black should be collapsing things down to one line when it fits? Thanks! |
That section isn't wrong or incorrect per se, but it is definitely is missing some finer points. Black would still collapse examples like these when it doesn't violate the line length limit and there is no trailing comma: this_is_a_tuple = (
1,
2,
3
) IMO what the section needs is an note that points to the "magic trailing comma" as it does go against "Black ignores previous formatting" (which is generally true, but not in this case). |
Hi,
First I would say I really love black, it is an awesome project that I have being using for years now.
I get that the trailing comma is a long standing bug that is now fixed, but I am somewhat not happy with the fix.
Black now does this :
[1,2,3]
stay as is[1,2,3,]
becomesPreviously the second example would have stay on one line.
This bothers me. A comma is not significant here, and as black removes useless parentheses or spaces, I would expect it removes the useless comma and keep my list on one line.
Now the style will be different if the dev added a useless comma or not.
More pernicious, look at this example :
Actually to synthesize what bothers me is that black does nothing when I have this
Those two lists are semantically identical, I would expect black to indent them the same way.
I get this is related to #826 and #1288, and this is a feature. But I don't really see the point. As black can add commas, I would expect it to remove commas to.
Thanks.
The text was updated successfully, but these errors were encountered: