Re:PEP 572: Python assignment expressions has been accepted
by junke on Tuesday July 03, 2018 @05:45AM
(#17448810)
Honestly curious, how do you expand a "x := y" expression into an expression that returns y and affects x as a side-effect?
[ Parent
| on HN ]
Re:PEP 572: Python assignment expressions has been accepted
by saltcured on Tuesday July 03, 2018 @01:08PM
(#17451883)
Does syntactic sugar have to be that strictly limited? If we are allowed to manipulate the statement block containing the sugared expression, we could define a trivial helper function which performs the 'nonlocal' side-effect and returns the value. Then, replace the "x := y" with "helper(y)".
Re:PEP 572: Python assignment expressions has been accepted
by akvadrako on Tuesday July 03, 2018 @07:23AM
(#17449244)
I'm not sure exactly, but my point is that a program transformation can do it. However, no transformation can change an import to other operations while perserving semantics.
Just for fun, this seems to work:
(locals().pop('x', None), locals().setdefault('x', y))[1]