Decorator Base Class: Needs improvement.

Kay Schluehr kay.schluehr at gmx.net
Tue Apr 5 03:54:25 EDT 2005


Steve Holden wrote:

> You have several times mentioned the possibility of a decorator
taking
> more than one argument, but in my understanding of decorators this
just
> wouldn't make sense. A decorator should (shouldn't it) take precisely

> one argument (a function or a method) and return precisely one value
(a
> decorated function or method).

Yes. I think this sould be fixed into the minds of the people exacly
this way You state it:

When writing

@decorator(x,y)
def f():
    ....

not the so called "decorator" function but decorator(x,y) is the
decorating function and decorator(x,y) is nothing but a callable object
that takes f as parameter. A little correcture of Your statement: it is
NOT nessacary that a function or method will be returned from a
decorator.

def decorator(x,y):
    def inner(func):
        return x+y
    return inner

@decorator(1,2)
def f():pass

>>> f
3

This is perfectly valid allthough not very usefull ;)

Regards,
Kay




More information about the Python-list mailing list