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

Juancarlo Añez apalala at gmail.com
Tue May 8 20:24:05 EDT 2018

> Implementation details - even just partial sketches - are always
> "busy".  Think of it this way instead:  it's _currently_ the case that
> listcomps & genexps run in a scope S that's the same as the scope C
> that contains them, _except_ that names appearing as `for` targets are
> local to S.  All other names in S resolve to exactly the same scopes
> they resolved to in C (local in C, global in C, nonlocal in C -
> doesn't matter).
> What changes now?  Nothing in that high-level description, except that
> a name appearing as a binding expression target in S that's otherwise
> unknown in C establishes that the name is local to C.  That's nothing
> essentially new, though - bindings _always_ establish scopes for
> otherwise-unknown names in Python.

That's a very nice (and short) explanation!

Maybe my distrust is just don't like the new syntax, or that I'am biased
towards using "as".

Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180508/501e1e5c/attachment.html>

More information about the Python-ideas mailing list