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:
konsti 2023-07-25 11:49:05 +02:00 committed by GitHub
parent 51d8fc1f30
commit e7f228f781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 383 additions and 352 deletions

View file

@ -101,3 +101,9 @@ x53 = (
a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlashdlfaskjfd.asdkjfksahdfkjafs
)
x6 = (
# Check assumption with enclosing nodes
a.b
)

View file

@ -2,14 +2,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
)

View file

@ -86,3 +86,16 @@ 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

View file

@ -99,3 +99,23 @@ 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