but not per class instancesuch that only the last instance is retained the solutionas in our prior class blunder for decorating methodslies in abandoning class-based decorators the earlier function-based tracer version does work for multiple instancesbecause each instance construction call makes new wrapper instanceinstead of overwriting the state of single shared tracer instancethe original nondecorator version handles multiple instances correctly for the same reason the moral heredecorators are not only arguably magicalthey can also be incredibly subtledecorators versus manager functions regardless of such subtletiesthe tracer class decorator example ultimately still relies on __getattr__ to intercept fetches on wrapped and embedded instance object as we saw earlierall we've really accomplished is moving the instance creation call inside classinstead of passing the instance into manager function with the original nondecorator tracing examplewe would simply code instance creation differentlyclass spamfood wrapper(spam()nondecorator version any class will do special creation syntax @tracer class spamfood spam(decorator version requires syntax at class normal creation syntax essentiallyclass decorators shift special syntax requirements from the instance creation call to the class statement itself this is also true for the singleton example earlier in this section--rather than decorating class and using normal instance creation callswe could simply pass the class and its construction arguments into manager functioninstances {def getinstance(aclass*args**kwargs)if aclass not in instancesinstances[aclassaclass(*args**kwargsreturn instances[aclassbob getinstance(person'bob' versusbob person('bob' alternativelywe could use python' introspection facilities to fetch the class from an already created instance (assuming creating an initial instance is acceptable)instances {def getinstance(object)aclass object __class__ if aclass not in instancesinstances[aclassobject return instances[aclassbob getinstance(person('bob' )versusbob person('bob' coding class decorators