[Python-Dev] Clarification on MRO when inheriting from builtin type.

Paul Sokolovsky pmiscml at gmail.com
Mon Apr 28 04:59:45 CEST 2014


Hello,

I used
http://python-history.blogspot.com/2010/06/method-resolution-order.html
and https://www.python.org/download/releases/2.3/mro/ as the reference,
but it doesn't explain MRO in the following example (python3.4):

~~~~
class User:
    def __str__(self):
        return "User.__str__"

    def append(self, a):
        print("User", a)

class C(list, User):
    pass

t = C([1, 2, 3])
print(t)
t.append(10)
print(t)
print(t[-1])
~~~~

The output is:

=====
User.__str__
User.__str__
10
=====

From the output, "User" class as expected does not override
list.append(), but does override list.__str__(). Is this behavior
documented somewhere (complete arrangement)? What's the rationale
behind it?

I need this info to implement MRO in an alternative Python
implementation (MicroPython).


Thanks,
 Paul                          mailto:pmiscml at gmail.com


More information about the Python-Dev mailing list