Hello,

It's more or less known fact (ref: google) that you can't inherit from
multiple generic builtin (as in "coded in C") types:

class C(dict, list): pass

TypeError: multiple bases have instance lay-out conflict

However, more detailed googling led me to this page of a book:
http://books.google.com.ua/books?id=JnR9hQA3SncC&pg=PA104&lpg=PA104 ,
which suggest that there might be adhoc support for some native types
to serve as multiple bases together, but it doesn't provide an example.
The book is apparently focused on Python2.

I tried to look at typeobject.c:best_base(), which throws the quoted
error above, and the only special rules I could quickly decipher from
it is that it's possible to multi-inherit from a class and its
subclass. Intuitively, it can be understood - it makes no sense to do
that on the same inheritance level, but can happen with recursive
inheritance, and then there's no need for conflict - both classes can be
"merged" into subclass.

Indeed, following works:

import _collections
class Foo(_collections.defaultdict, dict): pass

(opposite order gives MRO conflict)


So, is that it, or disjoint native types are supported as bases
somehow? Also, would someone know if a class-subclass case happens for
example in stdlib?

As the previous question,
https://mail.python.org/pipermail/python-dev/2014-April/134342.html
this one is to help set adequate requirements for implementing multiple
inheritance in MicroPython.


Thanks,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to