S
Stefan Behnel
Hi,
I just stumbled over this:
... A = x
... class X:
... a = A
... return X
...... A = x
... class X:
... A = A
... return X
...1
Works that way in Py2.7 and Py3.3.
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. Therefore, the A on the rhs is looked up in that
scope as well. However, this is just a totally hand waving guess.
Does anyone have a better explanation or know of a place where this
specific behaviour is documented?
Stefan
I just stumbled over this:
... A = x
... class X:
... a = A
... return X
...... A = x
... class X:
... A = A
... return X
...1
Works that way in Py2.7 and Py3.3.
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. Therefore, the A on the rhs is looked up in that
scope as well. However, this is just a totally hand waving guess.
Does anyone have a better explanation or know of a place where this
specific behaviour is documented?
Stefan