spam marked true def annotate(text)def decorate(func)func label text return func return decorate @annotate('spam data'def spam(ab)return samebut value is decorator argument spam annotate)(spamspam( )spam label ( 'spam data'such decorators augment functions and classes directlywithout catching later calls to them we'll see more examples of class decorations managing classes directly in the next because this turns out to encroach on the domain of metaclassesfor the remainder of this let' turn to two larger case studies of decorators at work example"privateand "publicattributes the final two sections of this present larger examples of decorator use both are presented with minimal descriptionpartly because this has hit its size limitsbut mostly because you should already understand decorator basics well enough to study these on your own being general-purpose toolsthese examples give us chance to see how decorator concepts come together in more useful code implementing private attributes the following class decorator implements private declaration for class instance attributes--that isattributes stored on an instanceor inherited from one of its classes it disallows fetch and change access to such attributes from outside the decorated classbut still allows the class itself to access those names freely within its own methods it' not exactly +or javabut it provides similar access control as an option in python we saw an incomplete first-cut implementation of instance attribute privacy for changes only in the version here extends this concept to validate attribute fetches tooand it uses delegation instead of inheritance to implement the model in factin sense this is just an extension to the attribute tracer class decorator we met earlier although this example utilizes the new syntactic sugar of class decorators to code attribute privacyits attribute interception is ultimately still based upon the __get attr__ and __setattr__ operator overloading methods we met in prior when decorators