[Python-ideas] Fixing class scope brainstorm

Guido van Rossum guido at python.org
Tue Mar 27 14:45:54 EDT 2018


On Tue, Mar 27, 2018 at 11:43 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

> On 03/27/2018 11:12 AM, Ivan Levkivskyi wrote:
>
>> On 27 March 2018 at 18:19, Guido van Rossum wrote:
>>
>
> Hm, so maybe we shouldn't touch lambda, but we can at least fix the scope
>>> issues for comprehensions and genexprs.
>>>
>>
>> Removing the implicit function scope in comprehensions is something I
>> wanted for long time.
>> It would not only "fix" the scoping, but will also fix the yield inside
>> comprehensions.
>>
>
> Can we do it without leaking names?
>

Assuming you're concerned about leaking names out of the comprehension into
the class scope, that shouldn't be a problem. (The solution actually
involves leaking names *into* the comprehension scope, but I'm not sure
that should be called "leaking". :-)

I do notice that we probably can't easily solve this using the existing
closure machinery ("cells") because if we were to have cells in the class
dict, it would confuse everything else that looks in the class namespace.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180327/f8230a5b/attachment.html>


More information about the Python-ideas mailing list