[Python-ideas] [Python-Dev] Tangent on class level scoping rules

Nick Coghlan ncoghlan at gmail.com
Sun Feb 23 23:15:10 CET 2014


On 24 Feb 2014 07:46, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
>
> Nick Coghlan wrote:
>
>> Dealing with references from nested closures is the hard part.
>
>
> I think that could be handled by creating new cells
> for the inner variables each time the inner scope
> is entered.

Yes, it's not hard * in theory*, it's just hard *in practice*, given the
current design of CPython's compiler - my perspective is informed by trying
to do it for comprehensions and eventually deciding "meh, I'll just use a
real closure so they behave *exactly* like generator expressions in a
constructor call and I can stop worrying about it".

There's also the fact that even after getting it to work, you have to
*document* it in the language reference as a new kind of scope, because it
doesn't behave the same way as any of the existing ones. Sure, it only
differs from a full closure in a few obscure edge cases, but it still
differs.

Cheers,
Nick.

>
> --
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140224/373eb298/attachment.html>


More information about the Python-ideas mailing list