PEP 318: Is chaining decorators even possible?

Michele Simionato mis6 at
Thu Jun 12 19:31:38 CEST 2003

Kevin Smith <Kevin.Smith at> wrote in message news:<20030612080349419-0400 at>...
> It has been brought up a couple of times in other threads that simply 
> chaining descriptors won't work (i.e. classmethod(synchronized(foo))).  
> Another possibility was to use subclassing (i.e. type('newtype',(
> classmethod,synchronized,{})(foo)).  When I wrote PEP 318, I wasn't sure 
> myself if it was possible to chain them, but I figured someone would 
> point it out if it wasn't.  So my question is, is it even possible to 
> chain decorators in a general way? 

Yes, it is. You can multiply inherit or use Steven Taschuk's solution
(see the revised PEP 318 thread). Both are not completely obvious and
require some effort to the user writing the custom descriptor. Nevertheless,
normal users should not write custom descriptors (at most they are expected 
to compose pre-defined descriptors), therefore I would not complain even
if the recipe to define composable decorators was a little trickier.
I think that probably classmethods and staticmethods would be reimplemented.


More information about the Python-list mailing list