besides generalizingthis version also makes use of python' __x pseudoprivate name mangling feature (which we met in to localize the wrapped attribute to the proxy control classby automatically prefixing it with this class' name this avoids the prior version' risk for collisions with wrapped attribute that may be used by the realwrapped classand it' useful in general tool like this it' not quite "privacy,thoughbecause the mangled version of the name can be used freely outside the class notice that we also have to use the fully expanded name string--'_oninstance__wrap ped'-as test value in __setattr__because that' what python changes it to breaking privacy although this example does implement access controls for attributes of an instance and its classesit is possible to subvert these controls in various ways--for instanceby going through the expanded version of the wrapped attribute explicitly (bob pay might not workbut the fully mangled bob _oninstance__wrapped pay could!if you have to explicitly try to do sothoughthese controls are probably sufficient for normal intended use of courseprivacy controls can generally be subverted in other languages if you try hard enough (#define private public may work in some +implementationstooalthough access controls can reduce accidental changesmuch of this is up to programmers in any languagewhenever source code may be changedairtight access control will always be bit of pipe dream decorator tradeoffs we could again achieve the same results without decoratorsby using manager functions or coding the name rebinding of decorators manuallythe decorator syntaxhowevermakes this consistent and bit more obvious in the code the chief potential downsides of this and any other wrapper-based approach are that attribute access incurs an extra calland instances of decorated classes are not really instances of the original decorated class--if you test their type with __class__ or isinstance(xc)for exampleyou'll find that they are instances of the wrapper class unless you plan to do introspection on objectstypesthoughthe type issue is probably irrelevantand the extra call may apply mostly to development timeas we'll see laterthere are ways to remove decorations automatically if desired open issues as isthis example works as planned under both python and for methods called explicitly by name as with most softwarethoughthere is always room for improvement most notablythis tool turns in mixed performance on operator overloading methods if they are used by client classes as codedthe proxy class is classic class when run under xbut new-style class when run by as suchthe code supports any client class in xbut in fails to example"privateand "publicattributes