Update Black tests (#13375)

This commit is contained in:
Micha Reiser 2024-09-17 11:16:50 +02:00 committed by GitHub
parent bb12fe9d0c
commit d86e5ad031
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 2653 additions and 24 deletions

View file

@ -0,0 +1 @@
{"target_version": "py310"}

View file

@ -0,0 +1,10 @@
class Plotter:
\
pass
class AnotherCase:
\
"""Some
\
Docstring
"""

View file

@ -0,0 +1,10 @@
class Plotter:
pass
class AnotherCase:
"""Some
\
Docstring
"""

View file

@ -2,5 +2,7 @@ def bob(): # pylint: disable=W9016
pass
def bobtwo(): # some comment here
def bobtwo():
# some comment here
pass

View file

@ -67,3 +67,63 @@ async def async_function(self):
@decorated
async def async_function(self):
...
class ClassA:
def f(self):
...
class ClassB:
def f(self):
...
class ClassC:
def f(self):
...
# Comment
class ClassD:
def f(self):# Comment 1
...# Comment 2
# Comment 3
class ClassE:
def f(self):
...
def f2(self):
print(10)
class ClassF:
def f(self):
...# Comment 2
class ClassG:
def f(self):#Comment 1
...# Comment 2
class ClassH:
def f(self):
#Comment
...

View file

@ -70,3 +70,47 @@ async def async_function(self): ...
@decorated
async def async_function(self): ...
class ClassA:
def f(self): ...
class ClassB:
def f(self): ...
class ClassC:
def f(self):
...
# Comment
class ClassD:
def f(self): # Comment 1
... # Comment 2
# Comment 3
class ClassE:
def f(self): ...
def f2(self):
print(10)
class ClassF:
def f(self): ... # Comment 2
class ClassG:
def f(self): # Comment 1
... # Comment 2
class ClassH:
def f(self):
# Comment
...

View file

@ -0,0 +1,13 @@
# Regression test for https://github.com/psf/black/issues/2478.
def foo():
arr = (
(3833567325051000, 5, 1, 2, 4229.25, 6, 0),
# fmt: off
)
# Regression test for https://github.com/psf/black/issues/3458.
dependencies = {
a: b,
# fmt: off
}

View file

@ -0,0 +1,13 @@
# Regression test for https://github.com/psf/black/issues/2478.
def foo():
arr = (
(3833567325051000, 5, 1, 2, 4229.25, 6, 0),
# fmt: off
)
# Regression test for https://github.com/psf/black/issues/3458.
dependencies = {
a: b,
# fmt: off
}

View file

@ -59,3 +59,61 @@ some_module.some_function(
some_module.some_function(
argument1, (one, two,), argument4, argument5, argument6
)
def foo() -> (
# comment inside parenthesised return type
int
):
...
def foo() -> (
# comment inside parenthesised return type
# more
int
# another
):
...
def foo() -> (
# comment inside parenthesised new union return type
int | str | bytes
):
...
def foo() -> (
# comment inside plain tuple
):
pass
def foo(arg: (# comment with non-return annotation
int
# comment with non-return annotation
)):
pass
def foo(arg: (# comment with non-return annotation
int | range | memoryview
# comment with non-return annotation
)):
pass
def foo(arg: (# only before
int
)):
pass
def foo(arg: (
int
# only after
)):
pass
variable: ( # annotation
because
# why not
)
variable: (
because
# why not
)

View file

@ -112,3 +112,75 @@ some_module.some_function(
argument5,
argument6,
)
def foo() -> (
# comment inside parenthesised return type
int
): ...
def foo() -> (
# comment inside parenthesised return type
# more
int
# another
): ...
def foo() -> (
# comment inside parenthesised new union return type
int
| str
| bytes
): ...
def foo() -> (
# comment inside plain tuple
):
pass
def foo(
arg: ( # comment with non-return annotation
int
# comment with non-return annotation
),
):
pass
def foo(
arg: ( # comment with non-return annotation
int
| range
| memoryview
# comment with non-return annotation
),
):
pass
def foo(arg: int): # only before
pass
def foo(
arg: (
int
# only after
),
):
pass
variable: ( # annotation
because
# why not
)
variable: (
because
# why not
)

View file

@ -6,7 +6,7 @@ def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parame
def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
# Adding some unformatted code covering a wide range of syntaxes.
# Adding some unformated code covering a wide range of syntaxes.
if True:
# Incorrectly indented prefix comments.

View file

@ -28,7 +28,7 @@ def foo3(
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
# Adding some unformatted code covering a wide range of syntaxes.
# Adding some unformated code covering a wide range of syntaxes.
if True:
# Incorrectly indented prefix comments.

View file

@ -0,0 +1,7 @@
# flags: --line-ranges=6-1000
# NOTE: If you need to modify this file, pay special attention to the --line-ranges=
# flag above as it's formatting specifically these lines.
def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass

View file

@ -0,0 +1,27 @@
# flags: --line-ranges=6-1000
# NOTE: If you need to modify this file, pay special attention to the --line-ranges=
# flag above as it's formatting specifically these lines.
def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo3(
parameter_1,
parameter_2,
parameter_3,
parameter_4,
parameter_5,
parameter_6,
parameter_7,
):
pass
def foo4(
parameter_1,
parameter_2,
parameter_3,
parameter_4,
parameter_5,
parameter_6,
parameter_7,
):
pass

View file

@ -82,7 +82,7 @@ match (0, 1, 2):
match x:
case [0]:
y = 0
case [1, 0] if (x := x[:0]):
case [1, 0] if x := x[:0]:
y = 1
case [1, 0]:
y = 2

View file

@ -82,7 +82,7 @@ match (0, 1, 2):
match x:
case [0]:
y = 0
case [1, 0] if (x := x[:0]):
case [1, 0] if x := x[:0]:
y = 1
case [1, 0]:
y = 2

View file

@ -0,0 +1 @@
{"preview": "enabled", "target_version": "py310"}

View file

@ -0,0 +1,32 @@
match match:
case "test" if case != "not very loooooooooooooog condition": # comment
pass
match smth:
case "test" if "any long condition" != "another long condition" and "this is a long condition":
pass
case test if "any long condition" != "another long condition" and "this is a looooong condition":
pass
case test if "any long condition" != "another long condition" and "this is a looooong condition": # some additional comments
pass
case test if (True): # some comment
pass
case test if (False
): # some comment
pass
case test if (True # some comment
):
pass # some comment
case cases if (True # some comment
): # some other comment
pass # some comment
case match if (True # some comment
):
pass # some comment
# case black_test_patma_052 (originally in the pattern_matching_complex test case)
match x:
case [1, 0] if x := x[:0]:
y = 1
case [1, 0] if (x := x[:0]):
y = 1

View file

@ -0,0 +1,36 @@
match match:
case "test" if case != "not very loooooooooooooog condition": # comment
pass
match smth:
case "test" if (
"any long condition" != "another long condition" and "this is a long condition"
):
pass
case test if (
"any long condition" != "another long condition"
and "this is a looooong condition"
):
pass
case test if (
"any long condition" != "another long condition"
and "this is a looooong condition"
): # some additional comments
pass
case test if True: # some comment
pass
case test if False: # some comment
pass
case test if True: # some comment
pass # some comment
case cases if True: # some comment # some other comment
pass # some comment
case match if True: # some comment
pass # some comment
# case black_test_patma_052 (originally in the pattern_matching_complex test case)
match x:
case [1, 0] if x := x[:0]:
y = 1
case [1, 0] if x := x[:0]:
y = 1

View file

@ -19,7 +19,7 @@ z: (Short
z: (int) = 2.3
z: ((int)) = foo()
# In case I go for not enforcing parentheses, this might get improved at the same time
# In case I go for not enforcing parantheses, this might get improved at the same time
x = (
z
== 9999999999999999999999999999999999999999

View file

@ -28,7 +28,7 @@ z: Short | Short2 | Short3 | Short4 = 8
z: int = 2.3
z: int = foo()
# In case I go for not enforcing parentheses, this might get improved at the same time
# In case I go for not enforcing parantheses, this might get improved at the same time
x = (
z
== 9999999999999999999999999999999999999999

View file

@ -0,0 +1 @@
{"target_version": "py312"}

View file

@ -0,0 +1,136 @@
x = f"foo"
x = f'foo'
x = f"""foo"""
x = f'''foo'''
x = f"foo {{ bar {{ baz"
x = f"foo {{ {2 + 2}bar {{ baz"
x = f'foo {{ {2 + 2}bar {{ baz'
x = f"""foo {{ {2 + 2}bar {{ baz"""
x = f'''foo {{ {2 + 2}bar {{ baz'''
# edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
x = f"{a} {b}"
x = f"foo {
2 + 2
} bar baz"
x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
x = """foo {{ {2 + 2}bar
baz"""
x = f"""foo {{ {2 + 2}bar {{ baz"""
x = f"""foo {{ {
2 + 2
}bar {{ baz"""
x = f"""foo {{ {
2 + 2
}bar
baz"""
x = f"""foo {{ a
foo {2 + 2}bar {{ baz
x = f"foo {{ {
2 + 2 # comment
}bar"
{{ baz
}} buzz
{print("abc" + "def"
)}
abc"""
# edge case: end triple quotes at index zero
f"""foo {2+2} bar
"""
f' \' {f"'"} \' '
f" \" {f'"'} \" "
x = f"a{2+2:=^72}b"
x = f"a{2+2:x}b"
rf'foo'
rf'{foo}'
f"{x:{y}d}"
x = f"a{2+2:=^{x}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
f'{(abc:=10)}'
f"This is a really long string, but just make sure that you reflow fstrings {
2+2:d
}"
f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
f"{2+2=}"
f"{2+2 = }"
f"{ 2 + 2 = }"
f"""foo {
datetime.datetime.now():%Y
%m
%d
}"""
f"{
X
!r
}"
raise ValueError(
"xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
f" {lines_str!r}"
)
f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
got {escape}"
x = f'\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}'
fr'\{{\}}'
f"""
WITH {f'''
{1}_cte AS ()'''}
"""
value: str = f'''foo
'''
log(
f"Received operation {server_operation.name} from "
f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
level=0,
)
f"{1:{f'{2}'}}"
f'{1:{f'{2}'}}'
f'{1:{2}d}'
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
f"""{'''
'''}"""
f"{'\''}"
f"{f'\''}"
f'{1}\{{'
f'{2} foo \{{[\}}'
f'\{3}'
rf"\{"a"}"

View file

@ -0,0 +1,136 @@
x = f"foo"
x = f"foo"
x = f"""foo"""
x = f"""foo"""
x = f"foo {{ bar {{ baz"
x = f"foo {{ {2 + 2}bar {{ baz"
x = f"foo {{ {2 + 2}bar {{ baz"
x = f"""foo {{ {2 + 2}bar {{ baz"""
x = f"""foo {{ {2 + 2}bar {{ baz"""
# edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
x = f"{a} {b}"
x = f"foo {
2 + 2
} bar baz"
x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
x = """foo {{ {2 + 2}bar
baz"""
x = f"""foo {{ {2 + 2}bar {{ baz"""
x = f"""foo {{ {
2 + 2
}bar {{ baz"""
x = f"""foo {{ {
2 + 2
}bar
baz"""
x = f"""foo {{ a
foo {2 + 2}bar {{ baz
x = f"foo {{ {
2 + 2 # comment
}bar"
{{ baz
}} buzz
{print("abc" + "def"
)}
abc"""
# edge case: end triple quotes at index zero
f"""foo {2+2} bar
"""
f' \' {f"'"} \' '
f" \" {f'"'} \" "
x = f"a{2+2:=^72}b"
x = f"a{2+2:x}b"
rf"foo"
rf"{foo}"
f"{x:{y}d}"
x = f"a{2+2:=^{x}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
f"{(abc:=10)}"
f"This is a really long string, but just make sure that you reflow fstrings {
2+2:d
}"
f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
f"{2+2=}"
f"{2+2 = }"
f"{ 2 + 2 = }"
f"""foo {
datetime.datetime.now():%Y
%m
%d
}"""
f"{
X
!r
}"
raise ValueError(
"xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
f" {lines_str!r}"
)
f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
got {escape}"
x = f"\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}"
rf"\{{\}}"
f"""
WITH {f'''
{1}_cte AS ()'''}
"""
value: str = f"""foo
"""
log(
f"Received operation {server_operation.name} from "
f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
level=0,
)
f"{1:{f'{2}'}}"
f"{1:{f'{2}'}}"
f"{1:{2}d}"
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
f"""{'''
'''}"""
f"{'\''}"
f"{f'\''}"
f"{1}\{{"
f"{2} foo \{{[\}}"
f"\{3}"
rf"\{"a"}"

View file

@ -173,3 +173,10 @@ this_will_also_become_one_line = ( # comment
"b"
"c"
)
assert some_var == expected_result, """
test
"""
assert some_var == expected_result, f"""
expected: {expected_result}
actual: {some_var}"""

View file

@ -207,3 +207,10 @@ this_will_stay_on_three_lines = (
)
this_will_also_become_one_line = "abc" # comment
assert some_var == expected_result, """
test
"""
assert some_var == expected_result, f"""
expected: {expected_result}
actual: {some_var}"""

View file

@ -0,0 +1 @@
{"preview": "enabled", "target_version": "py311"}

View file

@ -0,0 +1,5 @@
def fn(*args: *tuple[*A, B]) -> None:
pass
fn.__annotations__

View file

@ -0,0 +1,5 @@
def fn(*args: *tuple[*A, B]) -> None:
pass
fn.__annotations__

View file

@ -0,0 +1,23 @@
a = (
1 + # type: ignore
2 # type: ignore
)
a = (
1 # type: ignore
+ 2 # type: ignore
)
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
parametrize(
(
{},
{},
),
( # foobar
{},
{},
),
)

View file

@ -0,0 +1,23 @@
a = (
1 # type: ignore
+ 2 # type: ignore
)
a = (
1 # type: ignore
+ 2 # type: ignore
)
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
parametrize(
(
{},
{},
),
( # foobar
{},
{},
),
)

View file

@ -0,0 +1 @@
{"target_version": "py313"}

View file

@ -0,0 +1,19 @@
type A[T=int] = float
type B[*P=int] = float
type C[*Ts=int] = float
type D[*Ts=*int] = float
type D[something_that_is_very_very_very_long=something_that_is_very_very_very_long] = float
type D[*something_that_is_very_very_very_long=*something_that_is_very_very_very_long] = float
type something_that_is_long[something_that_is_long=something_that_is_long] = something_that_is_long
def simple[T=something_that_is_long](short1: int, short2: str, short3: bytes) -> float:
pass
def longer[something_that_is_long=something_that_is_long](something_that_is_long: something_that_is_long) -> something_that_is_long:
pass
def trailing_comma1[T=int,](a: str):
pass
def trailing_comma2[T=int](a: str,):
pass

View file

@ -0,0 +1,37 @@
type A[T = int] = float
type B[*P = int] = float
type C[*Ts = int] = float
type D[*Ts = *int] = float
type D[
something_that_is_very_very_very_long = something_that_is_very_very_very_long
] = float
type D[
*something_that_is_very_very_very_long = *something_that_is_very_very_very_long
] = float
type something_that_is_long[
something_that_is_long = something_that_is_long
] = something_that_is_long
def simple[
T = something_that_is_long
](short1: int, short2: str, short3: bytes) -> float:
pass
def longer[
something_that_is_long = something_that_is_long
](something_that_is_long: something_that_is_long) -> something_that_is_long:
pass
def trailing_comma1[
T = int,
](a: str):
pass
def trailing_comma2[
T = int
](a: str,):
pass

View file

@ -104,6 +104,9 @@ IGNORE_LIST = [
# Uses a different output format
"decorators.py",
# Tests line ranges that fall outside the source range. This is a CLI test case and not a formatting test case.
"line_ranges_outside_source.py",
]