Use space separator before parenthesiszed expressions in comprehensions with leading comments. (#12282)

This commit is contained in:
Micha Reiser 2024-07-11 22:38:12 +02:00 committed by GitHub
parent d0298dc26d
commit bd01004a42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 274 additions and 6 deletions

View file

@ -111,6 +111,69 @@ aaaaaaaaaaaaaaaaaaaaa = [
# Parenthesized targets and iterators.
[x for (x) in y]
[x for x in (y)]
# Leading expression comments:
y = [
a
for (
# comment
a
) in (
# comment
x
)
if (
# asdasd
"askldaklsdnmklasmdlkasmdlkasmdlkasmdasd"
!= "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
)
if (
# comment
x
)
]
# Tuple target:
y = [
a
for
# comment
a, b
in x
if True
]
y = [
a
for (
# comment
a, b
)
in x
if True
]
y = [
a
for
# comment
a
in
# comment
x
if
# asdasd
"askldaklsdnmklasmdlkasmdlkasmdlkasmdasd"
!= "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
if
# comment
x
]
```
## Output
@ -254,7 +317,104 @@ aaaaaaaaaaaaaaaaaaaaa = [
# Parenthesized targets and iterators.
[x for (x) in y]
[x for x in (y)]
# Leading expression comments:
y = [
a
for
(
# comment
a
) in
(
# comment
x
)
if
(
# asdasd
"askldaklsdnmklasmdlkasmdlkasmdlkasmdasd"
!= "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
)
if
(
# comment
x
)
]
# Tuple target:
y = [
a
for
# comment
a, b in x
if True
]
y = [
a
for (
# comment
a,
b,
) in x
if True
]
y = [
a
for
# comment
a in
# comment
x
if
# asdasd
"askldaklsdnmklasmdlkasmdlkasmdlkasmdasd" != "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
if
# comment
x
]
```
## Preview changes
```diff
--- Stable
+++ Preview
@@ -142,24 +142,20 @@
# Leading expression comments:
y = [
a
- for
- (
+ for (
# comment
a
- ) in
- (
+ ) in (
# comment
x
)
- if
- (
+ if (
# asdasd
"askldaklsdnmklasmdlkasmdlkasmdlkasmdasd"
!= "as,mdnaskldmlkasdmlaksdmlkasdlkasdm"
and "zxcm,.nzxclm,zxnckmnzxckmnzxczxc" != "zxcasdasdlmnasdlknaslkdnmlaskdm"
)
- if
- (
+ if (
# comment
x
)
```