#!/usr/local/bin/python2 from abc import abstractmethod from collections import Container, Iterable, Mapping, Sequence, Sized from array import array class Array(Sized, Iterable, Container): __slots__ = () __methods = '__getitem__', '__contains__', '__iter__', '__len__' @abstractmethod def __getitem__(self, key): raise KeyError def __contains__(self, value): return any(v == value for v in self) @classmethod def __subclasshook__(cls, C): if cls is Array and all(hasattr(C, method) for method in cls.__methods): return True return NotImplemented class MutableArray(Array): __slots__ = () __methods = ('__getitem__', '__setitem__', '__delitem__', '__contains__', '__iter__', '__len__') @abstractmethod def __setitem__(self, key, value): raise KeyError @abstractmethod def __delitem__(self, key): raise KeyError @classmethod def __subclasshook__(cls, C): if cls is MutableArray: if all(hasattr(C, method) for method in cls.__methods): return True return NotImplemented print issubclass(array, MutableArray)