-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
fmt: skip
on compound statements (#6593)
- Loading branch information
1 parent
4dc32a0
commit fa7442d
Showing
23 changed files
with
1,384 additions
and
624 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/match.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") |
31 changes: 31 additions & 0 deletions
31
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/or_else.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
20 changes: 20 additions & 0 deletions
20
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/parentheses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
28 changes: 28 additions & 0 deletions
28
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/type_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.