Revised PEP 318 - Function/Method Decorator Syntax

Michele Simionato mis6 at
Wed Jun 11 19:26:36 CEST 2003

Kevin Smith <Kevin.Smith at> wrote in message news:<20030610082514442-0400 at>...>     
> This syntax could also be extended to allow multiple function 
>     decorators in the form of a space delimited list as follows:
>        def protected classmethod foo(self):
>            perform method operation 
>     which would be equivalent to the current form:
>        def foo(self):
>            perform method operation
>        foo = protected(classmethod(foo))

I have just realized that there is an issue here.
IMHO, there is only one reasonable way of defining a "decorator": it
should be defined as a descriptor class, that takes a function and returns 
a descriptor object. classmethods and staticmethods work this way and 
"protected" should be the same. Now, if 'protected' is such a decorator, 
it would only accepts *functions* as input, not classmethod objects.


       def protected classmethod foo(self):
            perform method operation 

       def foo(self)[protected,classmethod]:
            perform method operation 

or whatever would give an error if interpreted as 

   foo = protected(classmethod(foo))

since protected would expect a function, not a classmethod object.

I think 'def foo(self)[protected,classmethod]' should be interpreted as


and protected.__init__ should be cooperative with classmethod.__init__.

IOW, the only thing that makes sense here is multiple inheritance,
not composition: descriptors are classes, not functions!


More information about the Python-list mailing list