classes and object-oriented programming this base class is then used as the parent for all objects that are to be documented for exampleclass foo(documented)spam(self, , )"spam does somethingpass this example illustrates one of the major uses of metaclasseswhich is that of inspecting and gathering information about class definitions the metaclass isn' changing anything about the class that actually gets created but is merely adding some additional checks in more advanced metaclass applicationsa metaclass can both inspect and alter the contents of class definition prior to the creation of the class if alterations are going to be madeyou should redefine the _new_ (method that runs prior to the creation of the class itself this technique is commonly combined with techniques that wrap attributes with descriptors or properties because it is one way to capture the names being used in the class as an examplehere is modified version of the typedproperty descriptor that was used in the "descriptorssectionclass typedproperty(object)def _init_ (self,type,default=none)self name none self type type if defaultself default default elseself default type(def _get_ (self,instance,cls)return getattr(instance,self name,self defaultdef _set_ (self,instance,value)if not isinstance(value,self type)raise typeerror("must be %sself typesetattr(instance,self name,valuedef _delete_ (self,instance)raise attributeerror("can' delete attribute"in this examplethe name attribute of the descriptor is simply set to none to fill this inwe'll rely on meta class for exampleclass typedmeta(type)def _new_ (cls,name,bases,dict)slots [for key,value in dict items()if isinstance(value,typedproperty)value name "_key slots append(value namedict[' _slots_ 'slots return type _new_ (cls,name,bases,dictbase class for user-defined objects to use class typedin python use the syntax _metaclass_ typedmeta class typed(metaclass=typedmetain this examplethe metaclass scans the class dictionary and looks for instances of typedproperty if foundit sets the name attribute and builds list of names in slots after this is donea _slots_ attribute is added to the class dictionaryand the class is constructed by calling the _new_ (method of the type(metaclass here is an example of using this new metaclassclass foo(typed)name typedproperty(strnum typedproperty(int, lib fl ff