Diamond inheritance with str
Patrick Earl
patrick at cs.ualberta.ca
Mon Jun 16 15:03:19 EDT 2003
Hi. I have the need to inherit from multiple classes that share the
same base class. This base class is a built in type like str, list,
float, or int.
The following works:
>>> class A(list): pass
...
>>> class B(list): pass
...
>>> class C(A,B): pass
...
>>>
It also seems to work for int and float. However, the following does
not work:
>>> class A(str): pass
...
>>> class B(str): pass
...
>>> class C(A,B): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: multiple bases have instance lay-out conflict
Why doesn't this inheritance structure work for strings? Is this a
bug?
Is there a good way to work around this? Using UserString allows the
inheritance, but I thought that UserString was considered obsolete due to
the ability to subclass built-in types.
I appreciate any thoughts on the matter. Thanks. :)
Patrick
PS. My apologies if this is a duplicate. I'm pretty sure it's not, but I
made a posting to python-list at python.org that didn't appear to go through.
More information about the Python-list
mailing list