as for function decoratorssome callable type combinations work better for class decorators than others consider the following invalid alternative to the class decorator of the prior exampleclass decoratordef __init__(selfc)on decoration self def __call__(self*args)on instance creation self wrapped self (*argsreturn self def __getattr__(selfattrname)on atrribute fetch return getattr(self wrappedattrname@decorator class cc decorator(cx ( (overwrites xthis code handles multiple decorated classes (each makes new decorator instanceand will intercept instance creation calls (each runs __call__unlike the prior versionhoweverthis version fails to handle multiple instances of given class--each instance creation call overwrites the prior saved instance the original version does support multiple instancesbecause each instance creation call makes new independent wrapper object more generallyeither of the following patterns supports multiple wrapped instancesdef decorator( )class wrapperdef __init__(self*args)self wrapped (*argsreturn wrapper class wrapperdef decorator( )def oncall(*args)return wrapper( (*args)return oncall on decoration on instance creationnew wrapper embed instance in instance on decoration on instance creationnew wrapper embed instance in instance we'll study this phenomenon in more realistic context later in the tooin practicethoughwe must be careful to combine callable types properly to support our intentand choose state policies wisely decorator nesting sometimes one decorator isn' enough for instancesuppose you've coded two function decorators to be used during development--one to test argument types before function callsand another to test return value types after function calls you can use either independentlybut what to do if you want to employ both on single functionwhat you really need is way to nest the twosuch that the result of one decorator is the basics