Author Brando753
Recipients Brando753, asvetlov, yselivanov
Date 2020-11-10.17:28:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605029315.25.0.963262062958.issue42316@roundup.psfhosted.org>
In-reply-to
Content
Reading the PEP 572 document I don't see anything stating that Walrus operator in list indexes must be enclosed in parenthesis. 

Minimal Example: 
'''
In [1]: a = list(range(10))

In [2]: idx = -1

In [3]: a[idx := idx +1]
  File "<ipython-input-3-65fc931e77dd>", line 1
    a[idx := idx +1]
          ^
SyntaxError: invalid syntax

'''

If you enclose in parenthesis it works as expected: 
'''
In [4]: a[(idx := idx +1)]
Out[4]: 0

In [5]: a[(idx := idx +1)]
Out[5]: 1

In [6]: a[(idx := idx +1)]
Out[6]: 2
'''

Is this a bug or am I misreading the PEP 572 document somewhere? It's not a top-level assignment nor is it a list comprehension so I would expect it to work in the first example.
History
Date User Action Args
2020-11-10 17:28:35Brando753setrecipients: + Brando753, asvetlov, yselivanov
2020-11-10 17:28:35Brando753setmessageid: <1605029315.25.0.963262062958.issue42316@roundup.psfhosted.org>
2020-11-10 17:28:35Brando753linkissue42316 messages
2020-11-10 17:28:35Brando753create