-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Preserve multiline aspect of a code chunk. #1476
Comments
The "magic trailing comma" should keep that collection exploded.
That seems like a bug to me. What version of Black are you running? Here's my output on master: (black) richard-26@ubuntu-laptop:~/programming$ cat test.py
test = [
1,
2,
3,
]
(black) richard-26@ubuntu-laptop:~/programming$ black test.py
reformatted test.py
All done! ✨ 🍰 ✨
1 file reformatted.
(black) richard-26@ubuntu-laptop:~/programming$ cat test.py
test = [
1,
2,
3,
] |
Hi @ichard26 is the magic trailing comma working yet for function and method calls? That's the one remaining thing that's preventing me from blacking 100% of my repositories. I cloned and installed the main Black repo today, but it looks like function-embedded magic commas are still forcibly conjoined:
|
Aha, I didn't realize this was a new feature. As of Here is how it looks on the latest stable:
|
Both of those are known bugs. Regarding the trailing comma bug within function calls, I think that's similar to these issues: Regarding the trailing comma even after Yeah, our issue tracker could do with a good cleanup, there are quite a few duplicates :-) EDIT: Also the "magic trailing comma" doesn't work on nested collections. |
If I have broken up a line of code that happens to fit within the line length limit, then black will reformat it into just one line. For example,
While I could prevent this by using
fmt: off
andfmt: on
around the affected lines, this can be quite invasive and litters the code, especially if you have many similar declarations within a module and you just want consistency of style (e.g. all declarations are multiline, even if they are short).So the only option is to disable black formatting for much larger code segements, which has obvious downsides like not reformating:
and not fixing any other formatting issues.
Might it be possible to tell black that we want it to preserve the multi-line aspect of code? That is, fix the other issues, but do not reformat it into just one line.
The text was updated successfully, but these errors were encountered: