[issue42316] Walrus Operator in list index

2020-11-16 Thread Lysandros Nikolaou


Lysandros Nikolaou  added the comment:


New changeset cae60187cf7a7b26281d012e1952fafe4e2e97e9 by Lysandros Nikolaou in 
branch 'master':
bpo-42316: Allow unparenthesized walrus operator in indexes (GH-23317)
https://github.com/python/cpython/commit/cae60187cf7a7b26281d012e1952fafe4e2e97e9


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42316] Walrus Operator in list index

2020-11-16 Thread Lysandros Nikolaou


Change by Lysandros Nikolaou :


--
nosy: +lys.nikolaou
nosy_count: 3.0 -> 4.0
pull_requests: +22208
pull_request: https://github.com/python/cpython/pull/23317

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42316] Walrus Operator in list index

2020-11-14 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
keywords: +patch
pull_requests: +22182
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23291

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42316] Walrus Operator in list index

2020-11-14 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

PEP 572 does not saw much of anything about when parens are needed.  Nor does 
the low priority itself.  Looking through the grammar of expressions, an 
assignment_expression is also a starred_expression, a positional_item (in 
calls), and the first part of a comprehension. It is not itself an plain 
expression unless and until wrapped in parentheses.  Subscription requires an 
expression list, which may be a single expression.

To put it another way: an expression is an assignment expression but an 
assignment expression with a "name :=" prefix is not an expression, so parens 
are required anywhere an expression is required.  That includes subscripts, 
slicings, displays, call items other than positional items, comprehension parts 
other than the initial expression (maybe, check), parts of conditional 
expressions (maybe, check), and lambda expression bodies.  After checking, I 
would like a sentence added to the doc before the 'go see the PEP' bit.

This has nothing to do with asyncio.

--
assignee:  -> docs@python
components: +Documentation, Interpreter Core -asyncio
nosy: +docs@python, terry.reedy -asvetlov, yselivanov
versions: +Python 3.10 -Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42316] Walrus Operator in list index

2020-11-10 Thread Brandon


New submission from Brandon :

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 "", 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.

--
components: asyncio
messages: 380691
nosy: Brando753, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Walrus Operator in list index
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com