Update some tests

This commit is contained in:
Jelle Zijlstra 2023-11-20 22:26:08 -08:00
parent c71b5e23bd
commit cc3780fd9f
19 changed files with 116 additions and 128 deletions

View File

@ -40,8 +40,7 @@
x = (0.000000006).hex() x = (0.000000006).hex()
x = -100.0000j x = -100.0000j
if (10).real: if (10).real: ...
...
y = 100[no] y = 100[no]
y = 100(no) y = 100(no)

View File

@ -45,8 +45,7 @@ def wat():
@deco2(with_args=True) @deco2(with_args=True)
# leading 3 # leading 3
@deco3 @deco3
def decorated1(): def decorated1(): ...
...
# leading 1 # leading 1
@ -54,8 +53,7 @@ def decorated1():
# leading 2 # leading 2
@deco2(with_args=True) @deco2(with_args=True)
# leading function comment # leading function comment
def decorated1(): def decorated1(): ...
...
# Note: this is fixed in # Note: this is fixed in
@ -65,8 +63,7 @@ def decorated1():
# This comment should be split from `some_instruction` by two lines but isn't. # This comment should be split from `some_instruction` by two lines but isn't.
def g(): def g(): ...
...
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -161,9 +161,7 @@ def tricky_asserts(self) -> None:
8 STORE_ATTR 0 (x) 8 STORE_ATTR 0 (x)
10 LOAD_CONST 0 (None) 10 LOAD_CONST 0 (None)
12 RETURN_VALUE 12 RETURN_VALUE
""" % ( """ % (_C.__init__.__code__.co_firstlineno + 1,)
_C.__init__.__code__.co_firstlineno + 1,
)
assert ( assert (
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect

View File

@ -347,9 +347,7 @@ def tricky_asserts(self) -> None:
8 STORE_ATTR 0 (x) 8 STORE_ATTR 0 (x)
10 LOAD_CONST 0 (None) 10 LOAD_CONST 0 (None)
12 RETURN_VALUE 12 RETURN_VALUE
""" % ( """ % (_C.__init__.__code__.co_firstlineno + 1,)
_C.__init__.__code__.co_firstlineno + 1,
)
assert ( assert (
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect

View File

@ -119,6 +119,7 @@ def f():
if not prev: if not prev:
prevp = preceding_leaf(p) prevp = preceding_leaf(p)
if not prevp or prevp.type in OPENING_BRACKETS: if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
if prevp.type == token.EQUAL: if prevp.type == token.EQUAL:

View File

@ -514,18 +514,12 @@ async def f():
force=False force=False
), "Short message" ), "Short message"
assert parens is TooMany assert parens is TooMany
for (x,) in (1,), (2,), (3,): for (x,) in (1,), (2,), (3,): ...
... for y in (): ...
for y in (): for z in (i for i in (1, 2, 3)): ...
... for i in call(): ...
for z in (i for i in (1, 2, 3)): for j in 1 + (2 + 3): ...
... while this and that: ...
for i in call():
...
for j in 1 + (2 + 3):
...
while this and that:
...
for ( for (
addr_family, addr_family,
addr_type, addr_type,

View File

@ -243,12 +243,8 @@ def spaces_types(
g: int = 1 if False else 2, g: int = 1 if False else 2,
h: str = "", h: str = "",
i: str = r"", i: str = r"",
): ): ...
... def spaces2(result=_core.Value(None)): ...
def spaces2(result=_core.Value(None)):
...
something = { something = {

View File

@ -161,8 +161,7 @@ def this_wont_be_formatted ( self ) -> str: ...
class Factory(t.Protocol): class Factory(t.Protocol):
def this_will_be_formatted(self, **kwargs) -> Named: def this_will_be_formatted(self, **kwargs) -> Named: ...
...
# fmt: on # fmt: on

View File

@ -114,8 +114,7 @@ def func_no_args():
c c
if True: if True:
raise RuntimeError raise RuntimeError
if False: if False: ...
...
for i in range(10): for i in range(10):
print(i) print(i)
continue continue
@ -158,10 +157,7 @@ def spaces_types(
g: int = 1 if False else 2, g: int = 1 if False else 2,
h: str = "", h: str = "",
i: str = r"", i: str = r"",
): ): ...
...
def spaces2(result=_core.Value(None)): def spaces2(result=_core.Value(None)):
assert fut is self._read_fut, (fut, self._read_fut) assert fut is self._read_fut, (fut, self._read_fut)

View File

@ -21,15 +21,21 @@ def http_status(status):
# output # output
def http_status(status): def http_status(status):
match status: match status:
case 400: case 400:
return "Bad request" return "Bad request"
case 401: case 401:
return "Unauthorized" return "Unauthorized"
case 403: case 403:
return "Forbidden" return "Forbidden"
case 404: case 404:
return "Not found" return "Not found"

View File

@ -254,10 +254,12 @@
+ CONCATENATED + CONCATENATED
+ "using the '+' operator." + "using the '+' operator."
) )
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped." annotated_variable: Final = (
annotated_variable: Literal[ "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
"fakse_literal" )
] = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped." annotated_variable: Literal["fakse_literal"] = (
"This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
)
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\" backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\" backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"

View File

@ -23,24 +23,18 @@
# output # output
with CtxManager() as example: with CtxManager() as example: ...
...
with CtxManager1(), CtxManager2(): with CtxManager1(), CtxManager2(): ...
...
with CtxManager1() as example, CtxManager2(): with CtxManager1() as example, CtxManager2(): ...
...
with CtxManager1(), CtxManager2() as example: with CtxManager1(), CtxManager2() as example: ...
...
with CtxManager1() as example1, CtxManager2() as example2: with CtxManager1() as example1, CtxManager2() as example2: ...
...
with ( with (
CtxManager1() as example1, CtxManager1() as example1,
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ): ...
...

View File

@ -24,10 +24,8 @@
def func(match: case, case: match) -> case: def func(match: case, case: match) -> case:
match Something(): match Something():
case func(match, case): case func(match, case): ...
... case another: ...
case another:
...
match a, *b, c: match a, *b, c:

View File

@ -1,8 +1,8 @@
# flags: --minimum-version=3.10 # flags: --minimum-version=3.10
# Unparenthesized walruses are now allowed in indices since Python 3.10. # Unparenthesized walruses are now allowed in indices since Python 3.10.
x[a:=0] x[a := 0]
x[a:=0, b:=1] x[a := 0, b := 1]
x[5, b:=0] x[5, b := 0]
# Walruses are allowed inside generator expressions on function calls since 3.10. # Walruses are allowed inside generator expressions on function calls since 3.10.
if any(match := pattern_error.match(s) for s in buffer): if any(match := pattern_error.match(s) for s in buffer):

View File

@ -96,12 +96,10 @@ async def await_the_walrus():
foo(x=(y := f(x))) foo(x=(y := f(x)))
def foo(answer=(p := 42)): def foo(answer=(p := 42)): ...
...
def foo2(answer: (p := 42) = 5): def foo2(answer: (p := 42) = 5): ...
...
lambda: (x := 1) lambda: (x := 1)

View File

@ -15,19 +15,16 @@ def f():
# output # output
@relaxed_decorator[0] @relaxed_decorator[0]
def f(): def f(): ...
...
@relaxed_decorator[ @relaxed_decorator[
extremely_long_name_that_definitely_will_not_fit_on_one_line_of_standard_length extremely_long_name_that_definitely_will_not_fit_on_one_line_of_standard_length
] ]
def f(): def f(): ...
...
@extremely_long_variable_name_that_doesnt_fit := complex.expression( @extremely_long_variable_name_that_doesnt_fit := complex.expression(
with_long="arguments_value_that_wont_fit_at_the_end_of_the_line" with_long="arguments_value_that_wont_fit_at_the_end_of_the_line"
) )
def f(): def f(): ...
...

View File

@ -3,14 +3,14 @@
def foo1(): def foo1():
print("The newline above me should be deleted!") print("The newline above me should be kept!")
def foo2(): def foo2():
print("All the newlines above me should be deleted!") print("All the newlines above me should be kept!")
def foo3(): def foo3():
@ -30,31 +30,31 @@ def foo4():
class Foo: class Foo:
def bar(self): def bar(self):
print("The newline above me should be deleted!") print("The newline above me should be kept!")
for i in range(5): for i in range(5):
print(f"{i}) The line above me should be removed!") print(f"{i}) The line above me should be kept!")
for i in range(5): for i in range(5):
print(f"{i}) The lines above me should be removed!") print(f"{i}) The lines above me should be kept!")
for i in range(5): for i in range(5):
for j in range(7): for j in range(7):
print(f"{i}) The lines above me should be removed!") print(f"{i}) The lines above me should be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
print("The new line above me is about to be removed!") print("The new line above me will be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
@ -62,43 +62,45 @@ def bar(self):
print("The new lines above me is about to be removed!") print("The new lines above me will be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
if random.uniform(0, 1) > 0.5: if random.uniform(0, 1) > 0.5:
print("Two lines above me are about to be removed!")
print("Two lines above me will be kept!")
while True: while True:
print("The newline above me should be deleted!") print("The newline above me should be kept!")
while True: while True:
print("The newlines above me should be deleted!") print("The newlines above me should be kept!")
while True: while True:
while False: while False:
print("The newlines above me should be deleted!") print("The newlines above me should be kept!")
with open("/path/to/file.txt", mode="w") as file: with open("/path/to/file.txt", mode="w") as file:
file.write("The new line above me is about to be removed!") file.write("The new line above me will be kept!")
with open("/path/to/file.txt", mode="w") as file: with open("/path/to/file.txt", mode="w") as file:
file.write("The new lines above me is about to be removed!") file.write("The new lines above me will be kept!")
with open("/path/to/file.txt", mode="r") as read_file: with open("/path/to/file.txt", mode="r") as read_file:
@ -113,20 +115,24 @@ def bar(self):
def foo1(): def foo1():
print("The newline above me should be deleted!")
print("The newline above me should be kept!")
def foo2(): def foo2():
print("All the newlines above me should be deleted!")
print("All the newlines above me should be kept!")
def foo3(): def foo3():
print("No newline above me!") print("No newline above me!")
print("There is a newline above me, and that's OK!") print("There is a newline above me, and that's OK!")
def foo4(): def foo4():
# There is a comment here # There is a comment here
print("The newline above me should not be deleted!") print("The newline above me should not be deleted!")
@ -134,56 +140,73 @@ def foo4():
class Foo: class Foo:
def bar(self): def bar(self):
print("The newline above me should be deleted!")
print("The newline above me should be kept!")
for i in range(5): for i in range(5):
print(f"{i}) The line above me should be removed!")
print(f"{i}) The line above me should be kept!")
for i in range(5): for i in range(5):
print(f"{i}) The lines above me should be removed!")
print(f"{i}) The lines above me should be kept!")
for i in range(5): for i in range(5):
for j in range(7): for j in range(7):
print(f"{i}) The lines above me should be removed!")
print(f"{i}) The lines above me should be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
print("The new line above me is about to be removed!")
print("The new line above me will be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
print("The new lines above me is about to be removed!")
print("The new lines above me will be kept!")
if random.randint(0, 3) == 0: if random.randint(0, 3) == 0:
if random.uniform(0, 1) > 0.5: if random.uniform(0, 1) > 0.5:
print("Two lines above me are about to be removed!")
print("Two lines above me will be kept!")
while True: while True:
print("The newline above me should be deleted!")
print("The newline above me should be kept!")
while True: while True:
print("The newlines above me should be deleted!")
print("The newlines above me should be kept!")
while True: while True:
while False: while False:
print("The newlines above me should be deleted!")
print("The newlines above me should be kept!")
with open("/path/to/file.txt", mode="w") as file: with open("/path/to/file.txt", mode="w") as file:
file.write("The new line above me is about to be removed!")
file.write("The new line above me will be kept!")
with open("/path/to/file.txt", mode="w") as file: with open("/path/to/file.txt", mode="w") as file:
file.write("The new lines above me is about to be removed!")
file.write("The new lines above me will be kept!")
with open("/path/to/file.txt", mode="r") as read_file: with open("/path/to/file.txt", mode="r") as read_file:
with open("/path/to/output_file.txt", mode="w") as write_file: with open("/path/to/output_file.txt", mode="w") as write_file:
write_file.writelines(read_file.readlines()) write_file.writelines(read_file.readlines())

View File

@ -75,15 +75,13 @@
with open("bla.txt") as f, open("x"): with open("bla.txt") as f, open("x"):
pass pass
with CtxManager1() as example1, CtxManager2() as example2: with CtxManager1() as example1, CtxManager2() as example2: ...
...
# Brackets remain when using magic comma # Brackets remain when using magic comma
with ( with (
CtxManager1() as example1, CtxManager1() as example1,
CtxManager2() as example2, CtxManager2() as example2,
): ): ...
...
# Brackets remain for multi-line context managers # Brackets remain for multi-line context managers
with ( with (
@ -92,8 +90,7 @@
CtxManager2() as example2, CtxManager2() as example2,
CtxManager2() as example2, CtxManager2() as example2,
CtxManager2() as example2, CtxManager2() as example2,
): ): ...
...
# Don't touch assignment expressions # Don't touch assignment expressions
with (y := open("./test.py")) as f: with (y := open("./test.py")) as f:
@ -116,5 +113,4 @@
with open("bla.txt") as f: with open("bla.txt") as f:
pass pass
with CtxManager1() as example1, CtxManager2() as example2: with CtxManager1() as example1, CtxManager2() as example2: ...
...

View File

@ -88,7 +88,6 @@ def foo() -> tuple[int, int, int,]:
return 2 return 2
# Magic trailing comma example, with params # Magic trailing comma example, with params
# this is broken - the trailing comma is transferred to the param list. Fixed in preview
def foo(a,b) -> tuple[int, int, int,]: def foo(a,b) -> tuple[int, int, int,]:
return 2 return 2
@ -194,30 +193,27 @@ def foo() -> tuple[int, int, int]:
return 2 return 2
def foo() -> ( def foo() -> tuple[
tuple[ loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, ]:
]
):
return 2 return 2
# Magic trailing comma example # Magic trailing comma example
def foo() -> ( def foo() -> tuple[
tuple[ int,
int, int,
int, int,
int, ]:
]
):
return 2 return 2
# Magic trailing comma example, with params # Magic trailing comma example, with params
# this is broken - the trailing comma is transferred to the param list. Fixed in preview def foo(a, b) -> tuple[
def foo( int,
a, b int,
) -> tuple[int, int, int,]: int,
]:
return 2 return 2