Problem subclassing tuple

Michele Simionato mis6 at
Wed Apr 30 14:44:24 CEST 2003

Skip Montanaro <skip at> wrote in message news:<mailman.1051645702.13393.python-list at>...
> >> You might want to make it "cooperative", that is, instead of using
>     >> "tuple.__new__", use "super(Holder,cls).__new__"
>     >> This delegates the search for the superclass to the function super();
>     >> and that gives you the ability to have multiple inheritance, since
>     >> super() will "do the right thing" when getting your current class'
>     >> superclass; so every class which defines a __new__ method has it
>     >> called.
> I don't believe it matters here.  As I recall, builtins don't support
> multiple inheritance very well (if at all).  The most you can do is add
> mixin classes.
> Skip

Indeed. According to Guido (see

 You can use multiple inheritance, but you can't multiply inherit from
different built-in types (for example, you can't create a type that 
inherits from both the built-indict and list types). This is a
permanent restriction; it would require too many changes to Python's
implementation to lift it. However, you can create mix-in classes by 
inheriting from "object".

Here is an exapmple for the OP's edification:

class Holder(tuple):
    def __new__(cls, *args, **kargs):
        return super(Holder,cls).__new__(cls, args)

class Pretty(object):
    def __str__(self):
        return '*** %s ***' % super(Pretty,self).__str__()

class PrettyHolder(Pretty,Holder): pass


print t  #=> *** (1, 2) ***

More information about the Python-list mailing list