mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 17:10:53 +00:00
Formatter: Implicit concatenation in compare expressions
## Summary This PR implements the logic for breaking implicit concatenated strings before compare expressions by building on top of #7145 The main change is a new `BinaryLike` enum that has the `BinaryExpression` and `CompareExpression` variants. Supporting both variants requires some downstream changes but doesn't introduce any new concepts. ## Test Plan I added a few more tests. The compatibility improvements are minor but we now perfectly match black on twine 🥳 **PR** | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | django | 0.99966 | 2760 | 58 | | transformers | 0.99928 | 2587 | 454 | | **twine** | 1.00000 | 33 | 0 | <-- improved | typeshed | 0.99978 | 3496 | 2173 | | **warehouse** | 0.99824 | 648 | 22 | <-- improved | zulip | 0.99948 | 1437 | 28 | **Base** | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1633 | | django | 0.99966 | 2760 | 58 | | transformers | 0.99928 | 2587 | 454 | | twine | 0.99982 | 33 | 1 | | typeshed | 0.99978 | 3496 | 2173 | | warehouse | 0.99823 | 648 | 23 | | zulip | 0.99948 | 1437 | 28 |
This commit is contained in:
parent
1d5c4b0a14
commit
c260762900
6 changed files with 444 additions and 160 deletions
|
@ -111,3 +111,61 @@ ct_match = (
|
|||
ct_match = (
|
||||
(aaaaaaaaaaaaaaaa) == self.get_content_type[obj, rel_obj, using, instance._state.db].id
|
||||
)
|
||||
|
||||
# comments
|
||||
|
||||
c = (
|
||||
1 > # 1
|
||||
# 2
|
||||
3 # 3
|
||||
> # 4
|
||||
5 # 5
|
||||
# 6
|
||||
)
|
||||
|
||||
# Implicit strings and comments
|
||||
|
||||
assert (
|
||||
"One or more packages has an associated PGP signature; these will "
|
||||
"be silently ignored by the index"
|
||||
in caplog.messages
|
||||
)
|
||||
|
||||
c = (a >
|
||||
# test leading binary comment
|
||||
"a" "b" * b
|
||||
)
|
||||
|
||||
c = (a *
|
||||
# test leading comment
|
||||
"a" "b" > b
|
||||
)
|
||||
|
||||
c = (a
|
||||
> # test trailing comment
|
||||
"a" "b" * b
|
||||
)
|
||||
|
||||
c = (a
|
||||
>
|
||||
"a" "b" # test trailing comment
|
||||
* b
|
||||
)
|
||||
|
||||
c = (a
|
||||
>
|
||||
"a" "b" # test trailing binary comment
|
||||
+ b
|
||||
)
|
||||
|
||||
|
||||
c = (a >
|
||||
# test leading binary comment
|
||||
"a" "b" * b
|
||||
)
|
||||
|
||||
c = (a *
|
||||
# test leading comment
|
||||
"a" "b" > b
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue