Format Slice Expressions (#5047)

This formats slice expressions and subscript expressions.

Spaces around the colons follows the same rules as black
(https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#slices):
```python
e00 = "e"[:]
e01 = "e"[:1]
e02 = "e"[: a()]
e10 = "e"[1:]
e11 = "e"[1:1]
e12 = "e"[1 : a()]
e20 = "e"[a() :]
e21 = "e"[a() : 1]
e22 = "e"[a() : a()]
e200 = "e"[a() : :]
e201 = "e"[a() :: 1]
e202 = "e"[a() :: a()]
e210 = "e"[a() : 1 :]
```

Comment placement is different due to our very different infrastructure.
If we have explicit bounds (e.g. `x[1:2]`) all comments get assigned as
leading or trailing to the bound expression. If a bound is missing
`[:]`, comments get marked as dangling and placed in the same section as
they were originally in:
```python
x = "x"[ # a
      # b
    :  # c
      # d
]
```
to
```python
x = "x"[
    # a
    # b
    :
    # c
    # d
]
```
Except for the potential trailing end-of-line comments, all comments get
formatted on their own line. This can be improved by keeping end-of-line
comments after the opening bracket or after a colon as such but the
changes were already complex enough.

I added tests for comment placement and spaces.
This commit is contained in:
konstin 2023-06-21 17:09:39 +02:00 committed by GitHub
parent 4634560c80
commit 6155fd647d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1065 additions and 430 deletions

View file

@ -73,9 +73,8 @@ y = 100(no)
+if 10 .NOT_IMPLEMENTED_attr:
...
-y = 100[no]
y = 100[no]
-y = 100(no)
+y = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+y = NOT_IMPLEMENTED_call()
```
@ -102,7 +101,7 @@ x = -100.0000J
if 10 .NOT_IMPLEMENTED_attr:
...
y = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
y = 100[no]
y = NOT_IMPLEMENTED_call()
```

View file

@ -264,32 +264,30 @@ instruction()#comment with bad spacing
if typedargslist:
- parameters.children = [children[0], body, children[-1]] # (1 # )1
- parameters.children = [
- children[0],
+ parameters.NOT_IMPLEMENTED_attr = [
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # (1
body,
- children[-1], # type: ignore
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # )1
+ children[0], # (1
+ body,
+ children[-1], # )1
+ ]
+ parameters.NOT_IMPLEMENTED_attr = [
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ body,
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: ignore
children[0],
body,
children[-1], # type: ignore
]
else:
- parameters.children = [
- parameters.children[0], # (2 what if this was actually long
+ parameters.NOT_IMPLEMENTED_attr = [
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # (2 what if this was actually long
+ parameters.NOT_IMPLEMENTED_attr[0], # (2 what if this was actually long
body,
- parameters.children[-1], # )2
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # )2
+ parameters.NOT_IMPLEMENTED_attr[-1], # )2
]
- parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
+ parameters.NOT_IMPLEMENTED_attr = [
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ parameters.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr[0],
+ body,
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ parameters.NOT_IMPLEMENTED_attr[-1],
+ ] # type: ignore
if (
- self._proc is not None
@ -460,25 +458,25 @@ else:
def inline_comments_in_brackets_ruin_everything():
if typedargslist:
parameters.NOT_IMPLEMENTED_attr = [
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # (1
children[0], # (1
body,
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # )1
children[-1], # )1
]
parameters.NOT_IMPLEMENTED_attr = [
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
children[0],
body,
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: ignore
children[-1], # type: ignore
]
else:
parameters.NOT_IMPLEMENTED_attr = [
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # (2 what if this was actually long
parameters.NOT_IMPLEMENTED_attr[0], # (2 what if this was actually long
body,
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # )2
parameters.NOT_IMPLEMENTED_attr[-1], # )2
]
parameters.NOT_IMPLEMENTED_attr = [
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
parameters.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr[0],
body,
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
parameters.NOT_IMPLEMENTED_attr[-1],
] # type: ignore
if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right

View file

@ -153,12 +153,9 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
tup = (
another_element,
@@ -84,35 +85,22 @@
@@ -86,33 +87,20 @@
def func(
- a=some_list[0], # type: int
+ a=NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: int
a=some_list[0], # type: int
): # type: () -> int
- c = call(
- 0.0123,
@ -293,7 +290,7 @@ def f(
def func(
a=NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: int
a=some_list[0], # type: int
): # type: () -> int
c = NOT_IMPLEMENTED_call()

View file

@ -276,7 +276,7 @@ last_call()
Name
None
True
@@ -30,203 +31,178 @@
@@ -30,134 +31,120 @@
-1
~int and not v1 ^ 123 + v2 | True
(~int) and (not ((v1 ^ (123 + v2)) | True))
@ -297,13 +297,6 @@ last_call()
-(str or None) if True else (str or bytes or None)
-str or None if (1 if True else 2) else str or bytes or None
-(str or None) if (1 if True else 2) else (str or bytes or None)
-(
- (super_long_variable_name or None)
- if (1 if super_long_test_name else 2)
- else (str or bytes or None)
-)
-{"2.7": dead, "3.7": (long_live or die_hard)}
-{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
++really ** -confusing ** ~operator**-precedence
+flags & ~select.NOT_IMPLEMENTED_attr and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+lambda x: True
@ -328,9 +321,7 @@ last_call()
+ "NOT_YET_IMPLEMENTED_STRING": (long_live or die_hard),
+ **{"NOT_YET_IMPLEMENTED_STRING": verygood},
+}
{**a, **b, **c}
-{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
-({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
+{**a, **b, **c}
+{
+ "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING",
@ -339,7 +330,16 @@ last_call()
+ "NOT_YET_IMPLEMENTED_STRING",
+ (NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false),
+}
+(
(
- (super_long_variable_name or None)
- if (1 if super_long_test_name else 2)
- else (str or bytes or None)
-)
-{"2.7": dead, "3.7": (long_live or die_hard)}
-{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
-{**a, **b, **c}
-{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
-({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
+ {"NOT_YET_IMPLEMENTED_STRING": "NOT_YET_IMPLEMENTED_STRING"},
+ (True or False),
+ (+value),
@ -352,7 +352,12 @@ last_call()
(1, 2, 3)
[]
[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
-[
+[1, 2, 3]
+[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5]
+[4, NOT_YET_IMPLEMENTED_ExprStarred, 5]
[
- 1,
- 2,
- 3,
@ -369,12 +374,7 @@ last_call()
- *a,
- 5,
-]
+[1, 2, 3]
+[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5]
+[4, NOT_YET_IMPLEMENTED_ExprStarred, 5]
[
-[
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
element,
another,
@ -393,6 +393,33 @@ last_call()
-{i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
-{a: b * 2 for a, b in dictionary.items()}
-{a: b * -2 for a, b in dictionary.items()}
-{
- k: v
- for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
-}
-Python3 > Python2 > COBOL
-Life is Life
-call()
-call(arg)
-call(kwarg="hey")
-call(arg, kwarg="hey")
-call(arg, another, kwarg="hey", **kwargs)
-call(
- this_is_a_very_long_variable_which_will_force_a_delimiter_split,
- arg,
- another,
- kwarg="hey",
- **kwargs,
-) # note: no trailing comma pre-3.6
-call(*gidgets[:2])
-call(a, *gidgets[:2])
-call(**self.screen_kwargs)
-call(b, **self.screen_kwargs)
-lukasz.langa.pl
-call.me(maybe)
-(1).real
-(1.0).real
-....__class__
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
@ -423,81 +450,22 @@ last_call()
+1 .NOT_IMPLEMENTED_attr
+1.0 .NOT_IMPLEMENTED_attr
+....NOT_IMPLEMENTED_attr
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign # type: ignore
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false
{
- k: v
- for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
+ "NOT_YET_IMPLEMENTED_STRING": dead,
+ "NOT_YET_IMPLEMENTED_STRING": long_live or die_hard,
}
-Python3 > Python2 > COBOL
-Life is Life
-call()
-call(arg)
-call(kwarg="hey")
-call(arg, kwarg="hey")
-call(arg, another, kwarg="hey", **kwargs)
-call(
- this_is_a_very_long_variable_which_will_force_a_delimiter_split,
- arg,
- another,
- kwarg="hey",
- **kwargs,
-) # note: no trailing comma pre-3.6
-call(*gidgets[:2])
-call(a, *gidgets[:2])
-call(**self.screen_kwargs)
-call(b, **self.screen_kwargs)
-lukasz.langa.pl
-call.me(maybe)
-(1).real
-(1.0).real
-....__class__
-list[str]
-dict[str, int]
-tuple[str, ...]
-tuple[str, int, float, dict[str, int]]
-tuple[
list[str]
dict[str, int]
tuple[str, ...]
tuple[str, int, float, dict[str, int]]
tuple[
- str,
- int,
- float,
- dict[str, int],
-]
+ (
+ str,
+ int,
+ float,
+ dict[str, int],
+ )
]
-very_long_variable_name_filters: t.List[
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
-]
@ -510,35 +478,43 @@ last_call()
-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
-) # type: ignore
-slice[0]
-slice[0:1]
-slice[0:1:2]
-slice[:]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+NOT_YET_IMPLEMENTED_StmtAnnAssign # type: ignore
slice[0]
slice[0:1]
slice[0:1:2]
slice[:]
-slice[:-1]
-slice[1:]
+slice[ : -1]
slice[1:]
-slice[::-1]
-slice[d :: d + 1]
-slice[:c, c - 1]
-numpy[:, 0:1]
+slice[ :: -1]
slice[d :: d + 1]
slice[:c, c - 1]
numpy[:, 0:1]
-numpy[:, :-1]
-numpy[0, :]
-numpy[:, i]
-numpy[0, :2]
-numpy[:N, 0]
-numpy[:2, :4]
-numpy[2:4, 1:5]
-numpy[4:, 2:]
-numpy[:, (0, 1, 2, 5)]
-numpy[0, [0]]
-numpy[:, [i]]
-numpy[1 : c + 1, c]
-numpy[-(c + 1) :, d]
-numpy[:, l[-2]]
+numpy[:, : -1]
numpy[0, :]
numpy[:, i]
numpy[0, :2]
@@ -171,62 +158,58 @@
numpy[1 : c + 1, c]
numpy[-(c + 1) :, d]
numpy[:, l[-2]]
-numpy[:, ::-1]
-numpy[np.newaxis, :]
-(str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
-{"2.7": dead, "3.7": long_live or die_hard}
-{"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
+numpy[:, :: -1]
+numpy[np.NOT_IMPLEMENTED_attr, :]
+NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false
+{
+ "NOT_YET_IMPLEMENTED_STRING": dead,
+ "NOT_YET_IMPLEMENTED_STRING": long_live or die_hard,
+}
+{
+ "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING",
@ -585,7 +561,13 @@ last_call()
-g = 1, *"ten"
-what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
- vars_to_remove
-)
+e = NOT_IMPLEMENTED_call()
+f = 1, NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = (
+ (coord_names + NOT_IMPLEMENTED_call())
+ + NOT_IMPLEMENTED_call()
)
-what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
- vars_to_remove
-)
@ -596,13 +578,7 @@ last_call()
- )
- .order_by(models.Customer.id.asc())
- .all()
+e = NOT_IMPLEMENTED_call()
+f = 1, NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = (
+ (coord_names + NOT_IMPLEMENTED_call())
+ + NOT_IMPLEMENTED_call()
)
-)
-result = (
- session.query(models.Customer.id)
- .filter(
@ -625,7 +601,7 @@ last_call()
mapping = {
A: 0.25 * (10.0 / 12),
B: 0.1 * (10.0 / 12),
@@ -236,64 +212,38 @@
@@ -236,64 +219,38 @@
def gen():
@ -714,7 +690,7 @@ last_call()
):
return True
if (
@@ -327,24 +277,44 @@
@@ -327,24 +284,44 @@
):
return True
if (
@ -771,7 +747,7 @@ last_call()
):
return True
(
@@ -363,8 +333,9 @@
@@ -363,8 +340,9 @@
bbbb >> bbbb * bbbb
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -908,41 +884,48 @@ NOT_IMPLEMENTED_call()
1 .NOT_IMPLEMENTED_attr
1.0 .NOT_IMPLEMENTED_attr
....NOT_IMPLEMENTED_attr
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
list[str]
dict[str, int]
tuple[str, ...]
tuple[str, int, float, dict[str, int]]
tuple[
(
str,
int,
float,
dict[str, int],
)
]
NOT_YET_IMPLEMENTED_StmtAnnAssign
NOT_YET_IMPLEMENTED_StmtAnnAssign
NOT_YET_IMPLEMENTED_StmtAnnAssign
NOT_YET_IMPLEMENTED_StmtAnnAssign # type: ignore
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
slice[0]
slice[0:1]
slice[0:1:2]
slice[:]
slice[ : -1]
slice[1:]
slice[ :: -1]
slice[d :: d + 1]
slice[:c, c - 1]
numpy[:, 0:1]
numpy[:, : -1]
numpy[0, :]
numpy[:, i]
numpy[0, :2]
numpy[:N, 0]
numpy[:2, :4]
numpy[2:4, 1:5]
numpy[4:, 2:]
numpy[:, (0, 1, 2, 5)]
numpy[0, [0]]
numpy[:, [i]]
numpy[1 : c + 1, c]
numpy[-(c + 1) :, d]
numpy[:, l[-2]]
numpy[:, :: -1]
numpy[np.NOT_IMPLEMENTED_attr, :]
NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false
{
"NOT_YET_IMPLEMENTED_STRING": dead,

View file

@ -273,7 +273,7 @@ d={'a':1,
+ debug: bool = False,
+ **kwargs,
+) -> str:
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ return text[number : -1]
+
+
# fmt: on
@ -296,7 +296,7 @@ d={'a':1,
def spaces_types(
@@ -51,76 +70,61 @@
@@ -51,76 +70,71 @@
d: dict = {},
e: bool = True,
f: int = -1,
@ -323,15 +323,22 @@ d={'a':1,
def subscriptlist():
- atom[
- # fmt: off
atom[
# fmt: off
- 'some big and',
- 'complex subscript',
- # fmt: on
- goes + here,
- andhere,
- ]
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ (
+ "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING",
+ # fmt: on
+ goes
+ + here,
+ andhere,
+ )
]
def import_as_names():
@ -390,7 +397,7 @@ d={'a':1,
# fmt: off
# hey, that won't work
@@ -130,13 +134,15 @@
@@ -130,13 +144,15 @@
def on_and_off_broken():
@ -411,7 +418,7 @@ d={'a':1,
# fmt: on
# fmt: off
# ...but comments still get reformatted even though they should not be
@@ -145,80 +151,21 @@
@@ -145,80 +161,21 @@
def long_lines():
if True:
@ -551,7 +558,7 @@ def function_signature_stress_test(
debug: bool = False,
**kwargs,
) -> str:
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
return text[number : -1]
# fmt: on
@ -595,7 +602,17 @@ something = {
def subscriptlist():
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
atom[
# fmt: off
(
"NOT_YET_IMPLEMENTED_STRING",
"NOT_YET_IMPLEMENTED_STRING",
# fmt: on
goes
+ here,
andhere,
)
]
def import_as_names():

View file

@ -167,7 +167,7 @@ def __await__(): return (yield)
**kwargs,
) -> str:
- return text[number:-1]
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ return text[number : -1]
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
@ -330,7 +330,7 @@ def function_signature_stress_test(
debug: bool = False,
**kwargs,
) -> str:
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
return text[number : -1]
def spaces(

View file

@ -94,7 +94,7 @@ some_module.some_function(
}
tup = (
1,
@@ -24,45 +24,18 @@
@@ -24,45 +24,23 @@
def f(
a: int = 1,
):
@ -106,7 +106,9 @@ some_module.some_function(
- call2(
- arg=[1, 2, 3],
- )
- x = {
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
x = {
- "a": 1,
- "b": 2,
- }["a"]
@ -123,9 +125,11 @@ some_module.some_function(
- "h": 8,
- }["a"]
- ):
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
+ x = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ "NOT_YET_IMPLEMENTED_STRING": 1,
+ "NOT_YET_IMPLEMENTED_STRING": 2,
+ }[
+ "NOT_YET_IMPLEMENTED_STRING"
+ ]
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
pass
@ -133,7 +137,7 @@ some_module.some_function(
-def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
- Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
-):
+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set["NOT_YET_IMPLEMENTED_STRING"]:
json = {
- "k": {
- "k2": {
@ -148,7 +152,7 @@ some_module.some_function(
}
@@ -80,35 +53,16 @@
@@ -80,35 +58,16 @@
pass
@ -221,12 +225,17 @@ def f(
):
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
x = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
x = {
"NOT_YET_IMPLEMENTED_STRING": 1,
"NOT_YET_IMPLEMENTED_STRING": 2,
}[
"NOT_YET_IMPLEMENTED_STRING"
]
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
pass
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set["NOT_YET_IMPLEMENTED_STRING"]:
json = {
"NOT_YET_IMPLEMENTED_STRING": {
"NOT_YET_IMPLEMENTED_STRING": {"NOT_YET_IMPLEMENTED_STRING": [1]},

View file

@ -25,25 +25,28 @@ list_of_types = [tuple[int,],]
```diff
--- Black
+++ Ruff
@@ -1,22 +1,12 @@
@@ -1,22 +1,17 @@
# We should not treat the trailing comma
# in a single-element subscript.
-a: tuple[int,]
-b = tuple[int,]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+b = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+b = tuple[(int,)]
# The magic comma still applies to multi-element subscripts.
-c: tuple[
- int,
- int,
-]
-d = tuple[
- int,
- int,
-]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
d = tuple[
- int,
- int,
+ (
+ int,
+ int,
+ )
]
# Magic commas still work as expected for non-subscripts.
-small_list = [
@ -53,7 +56,7 @@ list_of_types = [tuple[int,],]
- tuple[int,],
-]
+small_list = [1]
+list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]]
+list_of_types = [tuple[(int,)]]
```
## Ruff Output
@ -62,15 +65,20 @@ list_of_types = [tuple[int,],]
# We should not treat the trailing comma
# in a single-element subscript.
NOT_YET_IMPLEMENTED_StmtAnnAssign
b = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
b = tuple[(int,)]
# The magic comma still applies to multi-element subscripts.
NOT_YET_IMPLEMENTED_StmtAnnAssign
d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
d = tuple[
(
int,
int,
)
]
# Magic commas still work as expected for non-subscripts.
small_list = [1]
list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]]
list_of_types = [tuple[(int,)]]
```
## Black Output

View file

@ -92,7 +92,7 @@ return np.divide(
-j = super().name ** 5
-k = [(2**idx, value) for idx, value in pairs]
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
+d = 5 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+d = 5 ** f["NOT_YET_IMPLEMENTED_STRING"]
+e = NOT_IMPLEMENTED_call()
+f = NOT_IMPLEMENTED_call() ** 5
+g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr
@ -125,7 +125,7 @@ return np.divide(
-j = super().name ** 5.0
-k = [(2.0**idx, value) for idx, value in pairs]
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
+d = 5.0 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+d = 5.0 ** f["NOT_YET_IMPLEMENTED_STRING"]
+e = NOT_IMPLEMENTED_call()
+f = NOT_IMPLEMENTED_call() ** 5.0
+g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr
@ -181,7 +181,7 @@ def function_dont_replace_spaces():
a = 5**~4
b = 5 ** NOT_IMPLEMENTED_call()
c = -(5**2)
d = 5 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
d = 5 ** f["NOT_YET_IMPLEMENTED_STRING"]
e = NOT_IMPLEMENTED_call()
f = NOT_IMPLEMENTED_call() ** 5
g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr
@ -200,7 +200,7 @@ r = x**y
a = 5.0**~4.0
b = 5.0 ** NOT_IMPLEMENTED_call()
c = -(5.0**2.0)
d = 5.0 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
d = 5.0 ** f["NOT_YET_IMPLEMENTED_STRING"]
e = NOT_IMPLEMENTED_call()
f = NOT_IMPLEMENTED_call() ** 5.0
g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr

View file

@ -40,7 +40,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
-xxxxxxxxx_yyy_zzzzzzzz[
- xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)
-] = 1
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 1
+xxxxxxxxx_yyy_zzzzzzzz[NOT_IMPLEMENTED_call(), NOT_IMPLEMENTED_call()] = 1
```
## Ruff Output
@ -61,7 +61,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
# Make when when the left side of assignment plus the opening paren "... = (" is
# exactly line length limit + 1, it won't be split like that.
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 1
xxxxxxxxx_yyy_zzzzzzzz[NOT_IMPLEMENTED_call(), NOT_IMPLEMENTED_call()] = 1
```
## Black Output

View file

@ -123,35 +123,36 @@ def foo() -> tuple[int, int, int,]:
return 2
@@ -95,26 +99,14 @@
# Return type with commas
-def foo() -> tuple[int, int, int]:
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
@@ -99,22 +103,22 @@
return 2
-def foo() -> (
- tuple[
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
+def foo() -> tuple[
+ (
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
- ]
-):
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
+ )
+]:
return 2
# Magic trailing comma example
-def foo() -> (
- tuple[
- int,
- int,
- int,
+def foo() -> tuple[
+ (
int,
int,
int,
- ]
-):
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
+ )
+]:
return 2
```
@ -259,16 +260,28 @@ def foo() -> (
# Return type with commas
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
def foo() -> tuple[int, int, int]:
return 2
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
def foo() -> tuple[
(
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
)
]:
return 2
# Magic trailing comma example
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
def foo() -> tuple[
(
int,
int,
int,
)
]:
return 2
```

View file

@ -60,26 +60,31 @@ func(
```diff
--- Black
+++ Ruff
@@ -1,25 +1,30 @@
@@ -1,25 +1,35 @@
# We should not remove the trailing comma in a single-element subscript.
-a: tuple[int,]
-b = tuple[int,]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+b = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+b = tuple[(int,)]
# But commas in multiple element subscripts should be removed.
-c: tuple[int, int]
-d = tuple[int, int]
+NOT_YET_IMPLEMENTED_StmtAnnAssign
+d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+d = tuple[
+ (
+ int,
+ int,
+ )
+]
# Remove commas for non-subscripts.
small_list = [1]
-list_of_types = [tuple[int,]]
+list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]]
+list_of_types = [tuple[(int,)]]
small_set = {1}
-set_of_types = {tuple[int,]}
+set_of_types = {NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]}
+set_of_types = {tuple[(int,)]}
# Except single element tuples
small_tuple = (1,)
@ -108,17 +113,22 @@ func(
```py
# We should not remove the trailing comma in a single-element subscript.
NOT_YET_IMPLEMENTED_StmtAnnAssign
b = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
b = tuple[(int,)]
# But commas in multiple element subscripts should be removed.
NOT_YET_IMPLEMENTED_StmtAnnAssign
d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
d = tuple[
(
int,
int,
)
]
# Remove commas for non-subscripts.
small_list = [1]
list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]]
list_of_types = [tuple[(int,)]]
small_set = {1}
set_of_types = {NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]}
set_of_types = {tuple[(int,)]}
# Except single element tuples
small_tuple = (1,)

View file

@ -76,158 +76,137 @@ x[
```diff
--- Black
+++ Ruff
@@ -1,59 +1,48 @@
@@ -1,33 +1,33 @@
-slice[a.b : c.d]
-slice[d :: d + 1]
-slice[d + 1 :: d]
-slice[d::d]
-slice[0]
-slice[-1]
+slice[a.NOT_IMPLEMENTED_attr : c.NOT_IMPLEMENTED_attr]
slice[d :: d + 1]
slice[d + 1 :: d]
slice[d::d]
slice[0]
slice[-1]
-slice[:-1]
-slice[::-1]
-slice[:c, c - 1]
-slice[c, c + 1, d::]
-slice[ham[c::d] :: 1]
-slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
+slice[ : -1]
+slice[ :: -1]
slice[:c, c - 1]
slice[c, c + 1, d::]
slice[ham[c::d] :: 1]
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
-slice[:-1:]
-slice[lambda: None : lambda: None]
-slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
-slice[1 or 2 : True and False]
+slice[ : -1 :]
+slice[lambda x: True : lambda x: True]
+slice[lambda x: True :, None::]
slice[1 or 2 : True and False]
-slice[not so_simple : 1 < val <= 10]
-slice[(1 for i in range(42)) : x]
-slice[:: [i for i in range(42)]]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+slice[not so_simple : NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right]
+slice[(i for i in []) : x]
+slice[ :: [i for i in []]]
async def f():
- slice[await x : [i async for i in arange(42)] : 42]
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ slice[await x : [i for i in []] : 42]
# These are from PEP-8:
-ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
-ham[lower:upper], ham[lower:upper:], ham[lower::step]
+(
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+)
+(
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
+)
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
# ham[lower+offset : upper+offset]
-ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
-ham[lower + offset : upper + offset]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ham[ : NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()], ham[ :: NOT_IMPLEMENTED_call()]
ham[lower + offset : upper + offset]
-slice[::, ::]
-slice[
- # A
- :
- # B
- :
- # C
-]
-slice[
- # A
- 1:
- # B
- 2:
- # C
- 3
-]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
-slice[
- # A
- 1
slice[::, ::]
@@ -50,10 +50,14 @@
slice[
# A
1
- + 2 :
- # B
+ + 2 :
# B
- 3 :
- # C
- 4
-]
+ 3 :
# C
4
]
-x[1:2:3] # A # B # C
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+x[
+ 1: # A
+ 2: # B
+ 3 # C
+]
```
## Ruff Output
```py
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
slice[a.NOT_IMPLEMENTED_attr : c.NOT_IMPLEMENTED_attr]
slice[d :: d + 1]
slice[d + 1 :: d]
slice[d::d]
slice[0]
slice[-1]
slice[ : -1]
slice[ :: -1]
slice[:c, c - 1]
slice[c, c + 1, d::]
slice[ham[c::d] :: 1]
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
slice[ : -1 :]
slice[lambda x: True : lambda x: True]
slice[lambda x: True :, None::]
slice[1 or 2 : True and False]
slice[not so_simple : NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right]
slice[(i for i in []) : x]
slice[ :: [i for i in []]]
async def f():
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
slice[await x : [i for i in []] : 42]
# These are from PEP-8:
(
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
)
(
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key],
)
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
# ham[lower+offset : upper+offset]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
ham[ : NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()], ham[ :: NOT_IMPLEMENTED_call()]
ham[lower + offset : upper + offset]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
slice[::, ::]
slice[
# A
:
# B
:
# C
]
slice[
# A
1:
# B
2:
# C
3
]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
slice[
# A
1
+ 2 :
# B
3 :
# C
4
]
x[
1: # A
2: # B
3 # C
]
```
## Black Output

View file

@ -46,7 +46,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
```diff
--- Black
+++ Ruff
@@ -1,50 +1,26 @@
@@ -1,50 +1,30 @@
-zero(
- one,
-).two(
@ -86,7 +86,11 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
- },
- api_key=api_key,
- )["extensions"]["sdk"]["token"]
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
+ return NOT_IMPLEMENTED_call()["NOT_YET_IMPLEMENTED_STRING"][
+ "NOT_YET_IMPLEMENTED_STRING"
+ ][
+ "NOT_YET_IMPLEMENTED_STRING"
+ ]
# Edge case where a bug in a working-in-progress version of
@ -126,7 +130,11 @@ NOT_IMPLEMENTED_call()
# Example from https://github.com/psf/black/issues/3229
def refresh_token(self, device_family, refresh_token, api_key):
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
return NOT_IMPLEMENTED_call()["NOT_YET_IMPLEMENTED_STRING"][
"NOT_YET_IMPLEMENTED_STRING"
][
"NOT_YET_IMPLEMENTED_STRING"
]
# Edge case where a bug in a working-in-progress version of

View file

@ -0,0 +1,177 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
---
## Input
```py
# Handle comments both when lower and upper exist and when they don't
a1 = "a"[
# a
1 # b
: # c
2 # d
]
a2 = "a"[
# a
# b
: # c
# d
]
# Check all places where comments can exist
b1 = "b"[ # a
# b
1 # c
# d
: # e
# f
2 # g
# h
: # i
# j
3 # k
# l
]
# Handle the spacing from the colon correctly with upper leading comments
c1 = "c"[
1
: # e
# f
2
]
c2 = "c"[
1
: # e
2
]
c3 = "c"[
1
:
# f
2
]
c4 = "c"[
1
: # f
2
]
# End of line comments
d1 = "d"[ # comment
:
]
d2 = "d"[ # comment
1:
]
d3 = "d"[
1 # comment
:
]
# Spacing around the colon(s)
def a():
...
e00 = "e"[:]
e01 = "e"[:1]
e02 = "e"[: a()]
e10 = "e"[1:]
e11 = "e"[1:1]
e12 = "e"[1 : a()]
e20 = "e"[a() :]
e21 = "e"[a() : 1]
e22 = "e"[a() : a()]
e200 = "e"[a() :: ]
e201 = "e"[a() :: 1]
e202 = "e"[a() :: a()]
e210 = "e"[a() : 1 :]
```
## Output
```py
# Handle comments both when lower and upper exist and when they don't
a1 = "NOT_YET_IMPLEMENTED_STRING"[
# a
1 # b
: # c
2 # d
]
a2 = "NOT_YET_IMPLEMENTED_STRING"[
# a
# b
: # c
# d
]
# Check all places where comments can exist
b1 = "NOT_YET_IMPLEMENTED_STRING"[ # a
# b
1 # c
# d
: # e
# f
2 # g
# h
: # i
# j
3 # k
# l
]
# Handle the spacing from the colon correctly with upper leading comments
c1 = "NOT_YET_IMPLEMENTED_STRING"[
1: # e
# f
2
]
c2 = "NOT_YET_IMPLEMENTED_STRING"[
1: # e
2
]
c3 = "NOT_YET_IMPLEMENTED_STRING"[
1:
# f
2
]
c4 = "NOT_YET_IMPLEMENTED_STRING"[
1: # f
2
]
# End of line comments
d1 = "NOT_YET_IMPLEMENTED_STRING"[ # comment
:
]
d2 = "NOT_YET_IMPLEMENTED_STRING"[ # comment
1:
]
d3 = "NOT_YET_IMPLEMENTED_STRING"[
1 # comment
:
]
# Spacing around the colon(s)
def a():
...
e00 = "NOT_YET_IMPLEMENTED_STRING"[:]
e01 = "NOT_YET_IMPLEMENTED_STRING"[:1]
e02 = "NOT_YET_IMPLEMENTED_STRING"[ : NOT_IMPLEMENTED_call()]
e10 = "NOT_YET_IMPLEMENTED_STRING"[1:]
e11 = "NOT_YET_IMPLEMENTED_STRING"[1:1]
e12 = "NOT_YET_IMPLEMENTED_STRING"[1 : NOT_IMPLEMENTED_call()]
e20 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() :]
e21 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() : 1]
e22 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()]
e200 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() : :]
e201 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() :: 1]
e202 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() :: NOT_IMPLEMENTED_call()]
e210 = "NOT_YET_IMPLEMENTED_STRING"[NOT_IMPLEMENTED_call() : 1 :]
```