A metaclass is to a class what a class is to an instance; that is, a metaclass is used to create classes, just as classes are used to create instances. And just as we can ask whether an instance belongs to a class by using
isinstance(), we can ask whether a class object (such as
SortedList) inherits another class using
The simplest use of metaclasses is to make custom classes fit into Python’s standard ABC hierarchy. For example, to make
collections. Sequence, instead of inheriting the ABC (as we showed earlier), we can simply register the
SortedList as a
class SortedList: ...collections.Sequence.register(SortedList)
After the class is defined ...