mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Placement refactor (#6034)
## Summary This PR is a refactoring of placement.rs. The code got more consistent, some comments were updated and some dead code was removed or replaced with debug assertions. It also contains a bugfix for the placement of end-of-branch comments with nested bodies inside try statements that occurred when refactoring the nested body loop. ## Test Plan The existing test cases don't change. I added a couple of cases that i think should be tested but weren't, and a regression test for the bugfix
This commit is contained in:
parent
51d8fc1f30
commit
e7f228f781
10 changed files with 383 additions and 352 deletions
|
@ -107,6 +107,12 @@ x53 = (
|
|||
a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlashdlfaskjfd.asdkjfksahdfkjafs
|
||||
)
|
||||
|
||||
x6 = (
|
||||
# Check assumption with enclosing nodes
|
||||
a.b
|
||||
)
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -189,6 +195,11 @@ x8 = (a + a).b
|
|||
x51 = a.b.c
|
||||
x52 = a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlashdlfaskjfd.asdkjfksahdfkjafs
|
||||
x53 = a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlashdlfaskjfd.asdkjfksahdfkjafs
|
||||
|
||||
x6 = (
|
||||
# Check assumption with enclosing nodes
|
||||
a.b
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ call(
|
|||
# Leading starred comment
|
||||
* # Trailing star comment
|
||||
[
|
||||
# Leading value commnt
|
||||
# Leading value comment
|
||||
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||
] # trailing value comment
|
||||
)
|
||||
|
||||
call(
|
||||
# Leading starred comment
|
||||
* ( # Leading value commnt
|
||||
* ( # Leading value comment
|
||||
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||
) # trailing value comment
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ call(
|
|||
# Leading starred comment
|
||||
# Trailing star comment
|
||||
*[
|
||||
# Leading value commnt
|
||||
# Leading value comment
|
||||
[
|
||||
What,
|
||||
i,
|
||||
|
@ -42,7 +42,7 @@ call(
|
|||
|
||||
call(
|
||||
# Leading starred comment
|
||||
# Leading value commnt
|
||||
# Leading value comment
|
||||
*(
|
||||
[
|
||||
What,
|
||||
|
|
|
@ -92,6 +92,19 @@ def f():
|
|||
pass
|
||||
|
||||
# comment
|
||||
|
||||
if True:
|
||||
def f2():
|
||||
pass
|
||||
# 1
|
||||
else:
|
||||
def f2():
|
||||
pass
|
||||
# 2
|
||||
|
||||
if True: print("a") # 1
|
||||
elif True: print("b") # 2
|
||||
else: print("c") # 3
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -183,6 +196,23 @@ def f():
|
|||
pass
|
||||
|
||||
# comment
|
||||
|
||||
|
||||
if True:
|
||||
def f2():
|
||||
pass
|
||||
# 1
|
||||
else:
|
||||
def f2():
|
||||
pass
|
||||
# 2
|
||||
|
||||
if True:
|
||||
print("a") # 1
|
||||
elif True:
|
||||
print("b") # 2
|
||||
else:
|
||||
print("c") # 3
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -105,6 +105,26 @@ try:
|
|||
print(1) # issue7208
|
||||
except A:
|
||||
pass
|
||||
|
||||
try:
|
||||
f() # end-of-line last comment
|
||||
except RuntimeError:
|
||||
raise
|
||||
|
||||
try:
|
||||
def f2():
|
||||
pass
|
||||
# a
|
||||
except:
|
||||
def f2():
|
||||
pass
|
||||
# b
|
||||
|
||||
try: pass # a
|
||||
except ZeroDivisionError: pass # b
|
||||
except: pass # b
|
||||
else: pass # d
|
||||
finally: pass # c
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -220,6 +240,31 @@ try:
|
|||
print(1) # issue7208
|
||||
except A:
|
||||
pass
|
||||
|
||||
try:
|
||||
f() # end-of-line last comment
|
||||
except RuntimeError:
|
||||
raise
|
||||
|
||||
try:
|
||||
def f2():
|
||||
pass
|
||||
# a
|
||||
except:
|
||||
def f2():
|
||||
pass
|
||||
# b
|
||||
|
||||
try:
|
||||
pass # a
|
||||
except ZeroDivisionError:
|
||||
pass # b
|
||||
except:
|
||||
pass # b
|
||||
else:
|
||||
pass # d
|
||||
finally:
|
||||
pass # c
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue