way for examplein the __getattr__ operator overloading method is shown as way to wrap up entire object interfaces of embedded instancesin order to implement the delegation coding pattern we saw similar examples in the managed attribute coverage of the prior recall that __getattr__ is run when an undefined attribute name is fetchedwe can use this hook to intercept method calls in controller class and propagate them to an embedded object for referencehere' the original nondecorator delegation exampleworking on two built-in type objectsclass wrapperdef __init__(selfobject)self wrapped object def __getattr__(selfattrname)print('trace:'attrnamereturn getattr(self wrappedattrnamesave object trace fetch delegate fetch wrapper([ , , ] append( traceappend wrapped [ wrap list delegate to list method wrapper({" " " " }list( keys()tracekeys [' '' 'wrap dictionary delegate to dictionary method use list(in print my member in this codethe wrapper class intercepts access to any of the wrapped object' named attributesprints trace messageand uses the getattr built-in to pass off the request to the wrapped object specificallyit traces attribute accesses made outside the wrapped object' classaccesses inside the wrapped object' methods are not caught and run normally by design this whole-interface model differs from the behavior of function decoratorswhich wrap up just one specific method tracing interfaces with class decorators class decorators provide an alternative and convenient way to code this __getattr__ technique to wrap an entire interface as of both and for examplethe prior class example can be coded as class decorator that triggers wrapped instance creationinstead of passing premade instance into the wrapper' constructor (also augmented here to support keyword arguments with **kargs and to count the number of accesses made to illustrate changeable state)def tracer(aclass)class wrapperdef __init__(self*args**kargs)self fetches decorators on decorator on instance creation