Alex Martelli wrote:
def f(x):

... class C:
... x = x
... return C
...


[snip]

def f(x):

... def g():
... x = x
... return x
... return g
...


[snip]

See the difference? In a function, the 'x = x' compiles into LOAD_FAST, STORE_FAST, which only looks at locals and nowhere else. In a classbody, it compiles to LOAD_NAME, STORE_NAME, which looks at locals AND globals -- but still not at closure cells...

Is there a reason why the class body doesn't look at closure cells? That is, are there cases where this lookup scheme is preferred to one that checks locals, closure cells and globals?


Steve

P.S. Question disclaimer:
My questions here are founded in a curiosity about language design, and are not intended as an attack on Python. =)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to