Don't wrap with
statement with multiple context managers in parentheses when the line only overflows because of the last one
#4262
Labels
T: style
What do we want Blackened code to look like?
Describe the style change
As of version 24.1.0, Black now wraps multiple context managers in parentheses #3489
This is a great feature, but in some cases it's a bit too eager to reformat. When the line only overflows because of the last context manager in the with statement, wrapping everything in parentheses is a bit redundant and takes up a lot of vertical space. Previously, if the last context manager was already formatted to wrap over multiple lines, Black would leave it unchanged.
Examples in the current Black style
Desired style
This was the original input, left unchanged by Black prior to version 24.1.0
Additional context
Diff when updating Black mcbeet/mecha@2ac5ebe
This occurs a lot when using the
tokenstream
library. A singlewith
statement will often combine a few context managers to configure aTokenStream
for parsing. The last context manager is usually a list of token patterns that already wraps over multiple lines.The text was updated successfully, but these errors were encountered: