classes and object-oriented programming def _subclasscheck_ (self,sub)return any( in self implementors for in sub mro()nowuse the above object ifoo iclass(ifoo register(fooifoo register(fooproxyin this examplethe class iclass creates an object that merely groups collection of other classes together in set the register(method adds new class to the set the special method _instancecheck_ (is called if anyone performs the operation isinstance(xiclassthe special method _subclasscheck_ (is called if the operation issubclass( ,iclassis called by using the ifoo object and registered implementersone can now perform type checks such as the followingf foo(create foo fooproxy(fcreate fooproxy isinstance(fifooreturns true isinstance(gifooreturns true issubclass(fooproxyifooreturns true in this exampleit' important to emphasize that no strong type-checking is occurring the ifoo object has overloaded the instance checking operations in way that allows you to assert that class belongs to group it doesn' assert any information on the actual programming interfaceand no other verification actually occurs in factyou can simply register any collection of objects you want to group together without regard to how those classes are related to each other typicallythe grouping of classes is based on some criteria such as all classes implementing the same programming interface howeverno such meaning should be inferred when overloading _instancecheck_ (or _subclasscheck_ (the actual interpretation is left up to the application python provides more formal mechanism for grouping objectsdefining interfacesand type-checking this is done by defining an abstract base classwhich is defined in the next section abstract base classes in the last sectionit was shown that the isinstance(and issubclass(operations can be overloaded this can be used to create objects that group similar classes together and to perform various forms of type-checking abstract base classes build upon this concept and provide means for organizing objects into hierarchymaking assertions about required methodsand so forth to define an abstract base classyou use the abc module this module defines metaclass (abcmetaand set of decorators (@abstractmethod and @abstractpropertythat are used as followsfrom abc import abcmetaabstractmethodabstractproperty class fooin python you use the syntax _metaclass_ abcmeta class foo(metaclass=abcmeta@abstractmethod def spam(self, , )pass @abstractproperty lib fl ff