Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format StmtFor #5163

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
for x in y: # trailing test comment
pass # trailing last statement comment

# trailing for body comment

# leading else comment

else: # trailing else comment
pass

# trailing else body comment


for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn in anotherVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn: # trailing comment
pass

else:
...

for (
x,
y,
) in z: # comment
...


# remove brackets around x,y but keep them around z,w
for (x, y) in (z, w):
...


# type comment
for x in (): # type: int
...
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
```diff
--- Black
+++ Ruff
@@ -1,4 +1,3 @@
@@ -1,4 +1,6 @@
-for ((x in {}) or {})["a"] in x:
- pass
+for ((NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right) or {})[
+ "NOT_YET_IMPLEMENTED_STRING"
+] in x:
pass
-pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
-lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
+NOT_YET_IMPLEMENTED_StmtFor
+pem_spam = lambda x: True
+lambda x: True
```

## Ruff Output

```py
NOT_YET_IMPLEMENTED_StmtFor
for ((NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right) or {})[
"NOT_YET_IMPLEMENTED_STRING"
] in x:
pass
pem_spam = lambda x: True
lambda x: True
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if True:
```diff
--- Black
+++ Ruff
@@ -1,99 +1,56 @@
@@ -1,61 +1,40 @@
-import core, time, a
+NOT_YET_IMPLEMENTED_StmtImport
Expand Down Expand Up @@ -164,12 +164,10 @@ if True:
+NOT_YET_IMPLEMENTED_StmtAssert
# looping over a 1-tuple should also not get wrapped
-for x in (1,):
- pass
-for (x,) in (1,), (2,), (3,):
- pass
+NOT_YET_IMPLEMENTED_StmtFor
+NOT_YET_IMPLEMENTED_StmtFor
for x in (1,):
@@ -63,37 +42,17 @@
for (x,) in (1,), (2,), (3,):
pass
-[
- 1,
Expand Down Expand Up @@ -257,8 +255,10 @@ y = {
NOT_YET_IMPLEMENTED_StmtAssert
# looping over a 1-tuple should also not get wrapped
NOT_YET_IMPLEMENTED_StmtFor
NOT_YET_IMPLEMENTED_StmtFor
for x in (1,):
pass
for (x,) in (1,), (2,), (3,):
pass
[1, 2, 3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def func():
```diff
--- Black
+++ Ruff
@@ -3,46 +3,15 @@
@@ -3,46 +3,17 @@
# %%
def func():
Expand Down Expand Up @@ -97,7 +97,9 @@ def func():
- )
- # This should be left alone (after)
- )
+ NOT_YET_IMPLEMENTED_StmtFor
+ for exc in exc_value.NOT_IMPLEMENTED_attr:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call()
# everything is fine if the expression isn't nested
- traceback.TracebackException.from_exception(
Expand Down Expand Up @@ -128,7 +130,9 @@ def func():
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
if NOT_IMPLEMENTED_call():
embedded = []
NOT_YET_IMPLEMENTED_StmtFor
for exc in exc_value.NOT_IMPLEMENTED_attr:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call()
# everything is fine if the expression isn't nested
NOT_IMPLEMENTED_call()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if __name__ == "__main__":
```diff
--- Black
+++ Ruff
@@ -1,33 +1,20 @@
@@ -1,6 +1,6 @@
while True:
- if something.changed:
- do.stuff() # trailing comment
Expand All @@ -95,38 +95,40 @@ if __name__ == "__main__":
# Comment belongs to the `if` block.
# This one belongs to the `while` block.
# Should this one, too? I guess so.
@@ -8,26 +8,20 @@
# This one is properly standalone now.
-
-for i in range(100):
- # first we do this
+for i in NOT_IMPLEMENTED_call():
# first we do this
- if i % 33 == 0:
- break
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
break
- # then we do this
# then we do this
- print(i)
- # and finally we loop around
+NOT_YET_IMPLEMENTED_StmtFor
+ NOT_IMPLEMENTED_call()
# and finally we loop around
-with open(some_temp_file) as f:
- data = f.read()
-
+NOT_YET_IMPLEMENTED_StmtWith
-try:
- with open(some_other_file) as w:
- w.write(data)
+NOT_YET_IMPLEMENTED_StmtWith
+NOT_YET_IMPLEMENTED_StmtTry
-except OSError:
- print("problems")
+NOT_YET_IMPLEMENTED_StmtTry
-
-import sys
+NOT_YET_IMPLEMENTED_StmtImport
# leading function comment
@@ -42,7 +29,7 @@
@@ -42,7 +36,7 @@
# leading 1
@deco1
# leading 2
Expand All @@ -135,7 +137,7 @@ if __name__ == "__main__":
# leading 3
@deco3
def decorated1():
@@ -52,7 +39,7 @@
@@ -52,7 +46,7 @@
# leading 1
@deco1
# leading 2
Expand All @@ -144,7 +146,7 @@ if __name__ == "__main__":
# leading function comment
def decorated1():
...
@@ -69,5 +56,5 @@
@@ -69,5 +63,5 @@
...
Expand All @@ -167,7 +169,14 @@ while True:
# This one is properly standalone now.
NOT_YET_IMPLEMENTED_StmtFor
for i in NOT_IMPLEMENTED_call():
# first we do this
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
break
# then we do this
NOT_IMPLEMENTED_call()
# and finally we loop around
NOT_YET_IMPLEMENTED_StmtWith
Expand Down
Loading