from collections import *
class C(object):
def __iter__(self): pass
def __contains__(self, i): pass
def __len__(self): pass
def __getitem__(self, i): pass
issubclass(C, Mapping) => False
[issubclass(C, cls) for cls in Mapping.__mro__] => [False, True, True, True, True]
i.e. C does implement Sized, Iterable and Container.
I would have expected that just as issubclass(C, Sized) checks for the presence of a __len__ method, issubclass(C, Mapping) would check for the presence of the three methods required by each immediate superclass?
collections.Mappingis a mix-in class that provides the methods__contains__(),keys(),items(),values(),get(),__eq__()and__ne__()if you provide definitions of the methods__len__(),__iter__()and__getitem__(). For this to work, though, you need to derive fromMapping.If you don’t want to derive from
Mapping, you can also define all of the above-mentioned methods yourself and useto make
issubclass(C, Mapping)true.