[Python-ideas] Fixing class scope brainstorm

Guido van Rossum guido at python.org
Tue Mar 27 13:19:38 EDT 2018


On Tue, Mar 27, 2018 at 6:56 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> [...] The implicit functions used in the
> comprehension & generator expression cases are just potentially
> simpler to handle, as we don't care about their API signatures, which
> means we can freely pollute their APIs with eager name bindings if we
> choose to do so. [...]
>

Hm, so maybe we shouldn't touch lambda, but we can at least fix the scope
issues for comprehensions and genexprs.

There may still be breakage, when the code defines a global x that is
overridden by a class-level x, and a class-level comprehension references x
assuming it to be the global. So we need to tread carefully even here --
but this case is weird already:

x = 42
class C:
    x = [1, 2, 3]
    z = [x+y for y in x]  # [43, 44, 45]

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


More information about the Python-ideas mailing list