process class return @decorator class cc decorator(cto instead insert wrapper layer that intercepts later instance creation callsreturn different callable objectdef decorator( )save or use class return different callablenested defclass with __call__etc @decorator class cc decorator(cthe callable returned by such class decorator typically creates and returns new instance of the original classaugmented in some way to manage its interface for examplethe following inserts an object that intercepts undefined attributes of class instancedef decorator(cls)on decoration class wrapperdef __init__(self*args)on instance creation self wrapped cls(*argsdef __getattr__(selfname)on attribute fetch return getattr(self wrappednamereturn wrapper @decorator class cdef __init__(selfxy)self attr 'spamc decorator(crun by wrapper __init__ ( print( attrreally calls wrapper( runs wrapper __getattr__prints "spamin this examplethe decorator rebinds the class name to another classwhich retains the original class in an enclosing scope and creates and embeds an instance of the original class when it' called when an attribute is later fetched from the instanceit is intercepted by the wrapper' __getattr__ and delegated to the embedded instance of the original class moreovereach decorated class creates new scopewhich remembers the original class we'll flesh out this example into some more useful code later in this like function decoratorsclass decorators are commonly coded as either "factoryfunctions that create and return callablesclasses that use __init__ or __call__ methods to intercept call operationsor some combination thereof factory functions typically retain state in enclosing scope referencesand classes in attributes decorators