Hi,
I just stumbled over this:
A = 1
def foo(x):
... A = x
... class X:
... a = A
... return X
...
foo(2).a
2
def foo(x):
... A = x
... class X:
... A = A
... return X
...
foo(2).A
1
Works that way in Py2.7 and
Stefan Behnel, 15.08.2011 11:33:
I just stumbled over this:
A = 1
def foo(x):
... A = x
... class X:
... a = A
... return X
...
foo(2).a
2
def foo(x):
... A = x
... class X:
... A = A
... return X
...
foo(2).A
1
Works that way in
Stefan Behnel stefan...@behnel.de wrote:
I couldn't find any documentation on this, but my *guess* about the
reasoning is that the second case contains an assignment to A inside
of the class namespace, and assignments make a variable local to a
scope, in this case, the function scope.
Stefan Behnel wrote:
Hi,
I just stumbled over this:
A = 1
def foo(x):
... A = x
... class X:
... a = A
... return X
...
foo(2).a
2
def foo(x):
... A = x
... class X:
... A = A
... return X
Peter Otten wrote:
LOAD_NAME is pretty dumb, it looks into the local namespace and if that
lookup fails falls back to the global namespace. Someone probably thought I
can do better, and reused the static name lookup for nested functions for
names that occur only on the right-hand side of