Support fmt: skip on compound statements (#6593)

This commit is contained in:
Micha Reiser 2023-08-17 08:05:41 +02:00 committed by GitHub
parent 4dc32a00d0
commit fa7442da2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1385 additions and 625 deletions

View file

@ -0,0 +1,73 @@
def http_error(status):
match status : # fmt: skip
case 400 : # fmt: skip
return "Bad request"
case 404:
return "Not found"
case 418:
return "I'm a teapot"
case _:
return "Something's wrong with the internet"
# point is an (x, y) tuple
match point:
case (0, 0): # fmt: skip
print("Origin")
case (0, y):
print(f"Y={y}")
case (x, 0):
print(f"X={x}")
case (x, y):
print(f"X={x}, Y={y}")
case _:
raise ValueError("Not a point")
class Point:
x: int
y: int
def location(point):
match point:
case Point(x=0, y =0 ) : # fmt: skip
print("Origin is the point's location.")
case Point(x=0, y=y):
print(f"Y={y} and the point is on the y-axis.")
case Point(x=x, y=0):
print(f"X={x} and the point is on the x-axis.")
case Point():
print("The point is located somewhere else on the plane.")
case _:
print("Not a point")
match points:
case []:
print("No points in the list.")
case [
Point(0, 0)
]: # fmt: skip
print("The origin is the only point in the list.")
case [Point(x, y)]:
print(f"A single point {x}, {y} is in the list.")
case [Point(0, y1), Point(0, y2)]:
print(f"Two points on the Y axis at {y1}, {y2} are in the list.")
case _:
print("Something else is found in the list.")
match test_variable:
case (
'warning',
code,
40
): # fmt: skip
print("A warning has been received.")
case ('error', code, _):
print(f"An error {code} occurred.")
match point:
case Point(x, y) if x == y: # fmt: skip
print(f"The point is located on the diagonal Y=X at {x}.")
case Point(x, y):
print(f"Point is not on the diagonal.")

View file

@ -0,0 +1,31 @@
for item in container:
if search_something(item):
# Found it!
process(item)
break
# leading comment
else : #fmt: skip
# Didn't find anything..
not_found_in_container()
while i < 10:
print(i)
# leading comment
else : #fmt: skip
# Didn't find anything..
print("I was already larger than 9")
try : # fmt: skip
some_call()
except Exception : # fmt: skip
pass
except : # fmt: skip
handle_exception()
else : # fmt: skip
pass
finally : # fmt: skip
finally_call()

View file

@ -0,0 +1,20 @@
if (
# a leading condition comment
len([1, 23, 3, 4, 5]) > 2 # trailing condition comment
# trailing own line comment
): # fmt: skip
pass
if ( # trailing open parentheses comment
# a leading condition comment
len([1, 23, 3, 4, 5]) > 2
) and ((((y)))): # fmt: skip
pass
if ( # trailing open parentheses comment
# a leading condition comment
len([1, 23, 3, 4, 5]) > 2
) and y: # fmt: skip
pass

View file

@ -0,0 +1,28 @@
class TestTypeParam[ T ]: # fmt: skip
pass
class TestTypeParam [ # trailing open paren comment
# leading comment
T # trailing type param comment
# trailing type param own line comment
]: # fmt: skip
pass
class TestTrailingComment4[
T
] ( # trailing arguments open parenthesis comment
# leading argument comment
A # trailing argument comment
# trailing argument own line comment
): # fmt: skip
pass
def test [
# comment
A,
# another
B,
] (): # fmt: skip
...