issubclass(dict, Mapping)

Antoine Pitrou solipsis at pitrou.net
Wed Dec 22 09:44:01 EST 2010


On Wed, 22 Dec 2010 14:20:51 +0000 (UTC)
kj <no.email at please.post> wrote:
> 
> So dict is a subclass of Mapping, even though none of the bases of
> dict is either Mapping or a subclass of Mapping.  Great.
> 
> I suspect this is another abstraction leak ("dict is *supposed* to
> be a Python class like all others, but in fact it's not *really*.

It is. You just haven't read about Python's ABCs (abstract base
classes):

http://docs.python.org/library/abc.html#abc.ABCMeta

« You can also register unrelated concrete classes (even built-in
classes) and unrelated ABCs as “virtual subclasses” – these and their
descendants will be considered subclasses of the registering ABC by the
built-in issubclass() function, but the registering ABC won’t show up
in their MRO (Method Resolution Order) nor will method implementations
defined by the registering ABC be callable (not even via super()). »

With a very simple example in the register() doc:

http://docs.python.org/library/abc.html#abc.ABCMeta.register

Regards

Antoine.





More information about the Python-list mailing list