psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
39.27k stars 2.48k forks source link

Future of `string_processing` #4208

Open JelleZijlstra opened 10 months ago

JelleZijlstra commented 10 months ago

We merged string processing in May 2020 (#1132), almost four years ago. A few months later, I put the feature behind a flag because there were too many related bugs (#1609). Four years later, we're still in basically the same state: most of the open issues in https://github.com/psf/black/labels/C%3A%20preview%20style are about string processing.

I'm also increasingly convinced that string_processing's core feature, splitting up long strings, would be exceedingly controversial if we ever did turn it on by default. It is just too hard for a tool to figure out how to split a string in a way that makes sense to readers of the code. However, there are other things that string_processing does, and some of those are valuable and could perhaps be split off.

So my proposal is:

If you're interested in getting any part of string_processing into stable Black, please contribute a PR moving it to a separate preview feature.

I ran string_processing on my work codebase and noticed a few specific changes that could be split out. I'll list them in a separate comment.

JelleZijlstra commented 10 months ago

Here are some examples of changes that string-processing makes in my codebase that I'd consider accepting in a standalone preview feature:

zanieb commented 9 months ago

My 2-cents: I switched to Black's preview mode just for this feature. Otherwise, string processing is the vast majority of the time I spend manually formatting code. I would love to see this reach a place where it can be stabilized. I never had any problems with it, although I do understand there are many edge cases. I think splitting it into individual features makes a lot of sense so you can make incremental progress. I find splitting long strings really valuable, but understand it's a tough problem — we've been hesitant to tackle it in Ruff as well.

carschandler commented 5 months ago

Agreed with @zanieb this feature is the main reason I use Black over Ruff. Thinking about splitting all of my strings manually gives me Java-scented nightmares.