-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Summary
This is a silly contrived example, but unfortunately I cannot share the original code.
aa and bb are identical, except the comparisons are reordered. Both lines are 61 characters long.
foo = 5
aa = float("16.0") <= foo <= float("20.0") and 5 <= foo <= 10
bb = 5 <= foo <= 10 and float("16.0") <= foo <= float("20.0")When the line length is set to 60, this is the result (https://play.ruff.rs/56dffb27-828b-4cff-8903-5153da7ad31b?secondary=Format):
foo = 5
aa = (
float("16.0") <= foo <= float("20.0") and 5 <= foo <= 10
)
bb = 5 <= foo <= 10 and float("16.0") <= foo <= float(
"20.0"
)When the line length is set to 59, this is the result(https://play.ruff.rs/a9d7d7fb-1535-4600-9dde-1bd94bca876f?secondary=Format):
foo = 5
aa = (
float("16.0") <= foo <= float("20.0")
and 5 <= foo <= 10
)
bb = 5 <= foo <= 10 and float("16.0") <= foo <= float(
"20.0"
)In both cases, aa is obviously easier to read. Ideally, the formatter would format bb the same way.
In other words, putting an expression on a new line (in parentheses) or splitting on and should be preferred over splitting a function call's arguments into their own line.
However, this would be a deviation from Black, so I'm not really sure what could be done.