mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Mark trailing comments in parenthesized tests (#6287)
## Summary This ensures that we treat `# comment` as parenthesized in contexts like: ```python while ( True # comment ): pass ``` The same logic applies equally to `for`, `async for`, `if`, `with`, and `async with`. The general pattern is that you have an expression which precedes a colon-separated suite.
This commit is contained in:
parent
51ff98f9e9
commit
1705fcef36
5 changed files with 86 additions and 37 deletions
|
@ -193,16 +193,6 @@ class C:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -28,8 +28,8 @@
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
+ ):
|
||||
# Another
|
||||
- ):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
@@ -110,19 +110,20 @@
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
@ -293,8 +283,8 @@ class C:
|
|||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
):
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
|
|
|
@ -193,16 +193,6 @@ class C:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -28,8 +28,8 @@
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
+ ):
|
||||
# Another
|
||||
- ):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
@@ -110,19 +110,20 @@
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
@ -293,8 +283,8 @@ class C:
|
|||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
):
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
|
|
|
@ -144,6 +144,14 @@ else: # 7 preceding: last in body, following: fist in alt body, enclosing: exc
|
|||
print(3) # 8 preceding: last in body, following: fist in alt body, enclosing: try
|
||||
finally: # 9 preceding: last in body, following: fist in alt body, enclosing: try
|
||||
print(3) # 10 preceding: last in body, following: any, enclosing: try
|
||||
|
||||
try:
|
||||
pass
|
||||
except (
|
||||
ZeroDivisionError
|
||||
# comment
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -304,6 +312,14 @@ else: # 7 preceding: last in body, following: fist in alt body, enclosing: exc
|
|||
print(3) # 8 preceding: last in body, following: fist in alt body, enclosing: try
|
||||
finally: # 9 preceding: last in body, following: fist in alt body, enclosing: try
|
||||
print(3) # 10 preceding: last in body, following: any, enclosing: try
|
||||
|
||||
try:
|
||||
pass
|
||||
except (
|
||||
ZeroDivisionError
|
||||
# comment
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue