[issue44223] := in comprehensions does not work

2021-05-24 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Well, it works, but the priority of := is lower than priority of other 
operators. (x := item.upper() not in "ABC") is interpreted as (x := 
(item.upper() not in "ABC")).

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue44223] := in comprehensions does not work

2021-05-24 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

The parser rejects this ambiguity and requires parentheses:
[
xxx
for item in collection
if (xxx := mutator(item)) is not None
]

Example ambiguity:

>>> [x for item in "abcdefabc" if x := item.upper() not in "ABC"]
SyntaxError: invalid syntax
>>> [x for item in "abcdefabc" if (x := item.upper()) not in "ABC"]
['D', 'E', 'F']
>>> [x for item in "abcdefabc" if (x := item.upper() not in "ABC")]
[True, True, True]
>>>

--
nosy: +Dennis Sweeney

___
Python tracker 

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



[issue44223] := in comprehensions does not work

2021-05-24 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

"Does not work" is not informative. What did you get and what did you expect to 
get? Please proved a complete reproducible example.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue44223] := in comprehensions does not work

2021-05-24 Thread Марк Коренберг

New submission from Марк Коренберг :

[
xxx
for item in collection
if xxx := mutator(item) is not None
]

--
components: Interpreter Core, Parser
messages: 394233
nosy: lys.nikolaou, pablogsal, socketpair
priority: normal
severity: normal
status: open
title: := in comprehensions does not work
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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