[Python-ideas] @return?

Terry Reedy tjreedy at udel.edu
Wed Apr 14 18:41:59 CEST 2010


On 4/13/2010 5:36 PM, Conrad Irwin wrote:
> Dear All,
>
> I have an idea, though the acceptability of it is a matter for debate.
> It seems that this would be the appropriate place to post, but if not,
> or if you've already tired of this proposal, sorry.
>
> A common pattern when creating decorators is something of the form:
>
>      def decorator(func):
>          def wrapper(*args):
>              func(modulate(args))
>          return wrapper
>
> This is surprisingly reminiscent of the kind of code decorators were
> introduced to avoid:
>
>      class Example(object):
>          def method(cls, *args):
>              modulate(args)
>          method = classmethod(method)

Except that a) the decorator is written once and used many times and b) 
there is no need for a long name within the decorator. Def w and return 
w would suffice. One of the motivations for decorators was the need in 
certain applications to repeatedly wrap long names, with the consequent 
tedium and ease of misspelling and diffuculty of proof-reading. 
Something like

def some_required_to_be_long_name(): reutrn 1
some_required_to_be_long_name = wrapper(some_required_to_be_long_name).

Terry Jan Reedy




More information about the Python-ideas mailing list