Format symmetric list concatenations in preview - #5259
Conversation
|
diff-shades results comparing this PR (339735b) to main (e744e77):
|
cobaltt7
left a comment
There was a problem hiding this comment.
Similar to #5252, I really like this change and I think it looks cleaner, but it's a net LOC increase. Would appreciate input from other maintainers!
On the other hand, it looks like once the multiple lines issue is fixed, this won't end up affecting much already written code, because the second array that's currently broken across multiple lines has a trailing comma and won't be condensed. Hence in practice this only affects people running with -C, list comprehensions, and unformatted code. With the decreased scope it makes it easier to merge quickly
ef7bead to
13165c2
Compare
13165c2 to
79a44ca
Compare
values = (
["first_value", "second_value", "third_value"] # abc
+ ["fourth_value", "fifth_value", "sixth_value"]
)
values = (
["first_value", "second_value", "third_value"]
+ ["fourth_value", "fifth_value", "sixth_value"] # abc
)Comments at the end of the line should not restrict splitting |
Description
Closes #260.
When a long expression is exactly two list displays or comprehensions joined by one top-level
+, preserve its optional parentheses under--previewonly when each operand fits on its own delimiter-split line. This lets the existing delimiter splitter place each operand on its own line instead of exploding only the right-hand list. Long operands, active magic-trailing-comma layouts, stable style, short expressions, chained concatenations, and mixed operands keep their current behavior.The patch adds the preview feature flag, native format fixtures, schema entry, future-style documentation, changelog entry, and the required self-format dogfood change.
Validation:
env -u NO_COLOR tox -e py(480 passed, 1 skipped; Jupyter 73 passed)tox -e run_self,generate_schema-Wgit diff --checkChecklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?