> Maybe. For some languages this might be an obvious behavior, but
> Python would have different circumstances so it isn't so obvious (or
> possible) there.
Which means this topic definitely needs to be handled in detail by the
LR, and preferably also in the Tutorial. Otherwise there is no way
an
And by the way, the reason I've come across this problem at all is
because I have something like this:
class A:
class X:
n = 'a'
x = X()
class B(A):
class X(A.X):
n = 'b'
# x = X()
The line commented out was originally not there, but I found out I had
to add it if I wanted B().x.n
> http://docs.python.org/reference/datamodel.html#new-style-and-classic...
> - search for 'method resolution order' for other hits in that document.
First of all, that's the LR for Python 2, I'm with Python 3. Second of
all, there's one single passage containing the phrase "method
resolution order
> Conceptually, Python checks for the presence of B.foo, and if it's
> not there it checks for foo's presence in the base classes.
Yes, I have no problem believing you guys that this is what Python
does. Still, my question remains about where in the Language Reference
this is specified. And if the
> would you expect the B class to have a copy of the foo method?
Sorta. I would expect B to have a copy of the "foo" attribute, which
then refers to the same method as A.foo. So the method itself will be
be copied, but its address stored separately in A.foo and B.foo.
--
http://mail.python.org/ma
> I could, but I will let you read and find what it says about class
> attributes.
You think I would have asked specifically about the Language Reference
if I hadn't read it and failed to find what I was looking for?
The closest thing I was able to find was section 3.2. "The standard
type hierarc
> Makes sense to me. To step through what's happening:
>
> >>> A.n, B.n
> (0, 0)
>
> Here, the lookup on B.n fails (that is, B itself has no variable n),
> and thus falls back to A.n
See, this is what tripped me up, right at the beginning. I thought B
would inherit (as in copy) the variable n from