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

Juancarlo Añez apalala at gmail.com
Tue May 8 13:28:59 EDT 2018


So the way I envision it is that *in the absence of a nonlocal or global
> declaration in the containing scope*, := inside a comprehension or genexpr
> causes the compiler to assign to a local in the containing scope, which is
> elevated to a cell (if it isn't already). If there is an explicit nonlocal
> or global declaration in the containing scope, that is honored.
>

This seems to be getting awfully complicated. Proof? Try to write the docs
for the proposed semantics.

I don't understand why we went so astray from the original requirements,
which could all be met by having `if` and `while` accept `as` to bind an
expression to a variable that would be local to the structured statement.

Cheers,

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


More information about the Python-ideas mailing list