Revised PEP 318 - Function/Method Decorator Syntax
Michele Simionato
mis6 at pitt.edu
Wed Jun 11 13:26:36 EDT 2003
Kevin Smith <Kevin.Smith at sas.com> wrote in message news:<20030610082514442-0400 at braeburn.themorgue.org>...>
> 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.
Therefore
def protected classmethod foo(self):
perform method operation
or
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
foo=type('protectedclassmethod',(protected,classmethod),{})(foo)
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!
Michele
More information about the Python-list
mailing list