mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Format Compare Op
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR adds basic formatting for compare operations. The implementation currently breaks diffeently when nesting binary like expressions. I haven't yet figured out what Black's logic is in that case but I think that this by itself is already an improvement worth merging. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan I added a few new tests <!-- How was it tested? -->
This commit is contained in:
parent
2142bf6141
commit
3e12bdff45
24 changed files with 735 additions and 244 deletions
61
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/compare.py
vendored
Normal file
61
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/compare.py
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
a == b
|
||||
a != b
|
||||
a < b
|
||||
a <= b
|
||||
a > b
|
||||
a >= b
|
||||
a is b
|
||||
a is not b
|
||||
a in b
|
||||
a not in b
|
||||
|
||||
(a ==
|
||||
# comment
|
||||
b
|
||||
)
|
||||
|
||||
(a == # comment
|
||||
b
|
||||
)
|
||||
|
||||
a < b > c == d
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ccccccccccccccccccccccccccccc == ddddddddddddddddddddd
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||
ff,
|
||||
] < [ccccccccccccccccccccccccccccc, dddd] < ddddddddddddddddddddddddddddddddddddddddddd
|
||||
|
||||
return 1 == 2 and (
|
||||
name,
|
||||
description,
|
||||
self_default,
|
||||
self_selected,
|
||||
self_auto_generated,
|
||||
self_parameters,
|
||||
self_meta_data,
|
||||
self_schedule,
|
||||
) == (
|
||||
name,
|
||||
description,
|
||||
othr_default,
|
||||
othr_selected,
|
||||
othr_auto_generated,
|
||||
othr_parameters,
|
||||
othr_meta_data,
|
||||
othr_schedule,
|
||||
)
|
||||
|
||||
(name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule)
|
||||
((name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule))
|
||||
|
||||
[
|
||||
(
|
||||
a
|
||||
+ [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
]
|
||||
>= c
|
||||
)
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue