[Python-ideas] A comprehension scope issue in PEP 572

Tim Peters tim.peters at gmail.com
Mon May 7 20:54:17 EDT 2018


[Tim]
> ... The ":= is treated specially in comprehensions" idea is aimed
> more at them than at people who think invoking a synthetic
> anonymous lambda "is obvious".

It occurs to me that, while suggestive, this is an unhelpful way to
express it.  It's not at all that the semantics of ":=" change inside
a listcomp/genexp, it's that the latter's idea of intended _scopes_
for names is made more nuanced (inside a synthetic function created to
implement a listcomp/genexp, names bound by "=" are local; names bound
by ":=" are nonlocal; names bound by both are "who cares?"-
compiler-time error would be fine by me, or the first person to show a
real use case wins).

Regardless, the runtime implementation of ":=" remains the same everywhere.


More information about the Python-ideas mailing list