Avoid searching for bracketed comments in unparenthesized generators (#7627)

Similar to tuples, a generator _can_ be parenthesized or
unparenthesized. Only search for bracketed comments if it contains its
own parentheses.

Closes https://github.com/astral-sh/ruff/issues/7623.
This commit is contained in:
Charlie Marsh 2023-09-23 22:08:44 -04:00 committed by GitHub
parent 1a22eae98c
commit 865c89800e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 7 deletions

View file

@ -58,6 +58,23 @@ a = (
aaaaaaaaaaaaaaaaaaaaa = (
o for o in self.registry.values if o.__class__ is not ModelAdmin
)
# Regression test for: https://github.com/astral-sh/ruff/issues/7623
tuple(
0 # comment
for x in y
)
tuple(
(0 # comment
for x in y)
)
tuple(
( # comment
0 for x in y
)
)
```
## Output
@ -122,6 +139,25 @@ a = (
aaaaaaaaaaaaaaaaaaaaa = (
o for o in self.registry.values if o.__class__ is not ModelAdmin
)
# Regression test for: https://github.com/astral-sh/ruff/issues/7623
tuple(
0 # comment
for x in y
)
tuple(
(
0 # comment
for x in y
)
)
tuple(
( # comment
0 for x in y
)
)
```