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
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
>>>
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
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