[Python-Dev] Proposed tweaks to functools.wraps

Guido van Rossum guido at python.org
Wed Aug 11 05:55:56 CEST 2010


On Tue, Aug 10, 2010 at 8:22 PM, Steve Holden <steve at holdenweb.com> wrote:
> One of the things that's slightly irking about the decorator syntax is
> that a decorator is always called with exactly one argument, and that if
> you want to write a parameterized decorator you therefore end up writing
> a function that returns a function that returns a function.
>
> I've scratched my head about how partials (or indeed anything else)
> could be used to make the extra level of indirection necessary, but
> haven' come up with anything that even I could regard as acceptable. But
> I can't escape this feeling that there must be a way.

Someone at EuroPython brought up this very criticism.

But my argument against it is: you should be able to write either

  @bar(args)
  def func(): ...

or

  foo = bar(args)
  @foo
  def func(): ...

and you should be able to predict how these two relate using standard
knowledge about what it means to say

  foo = bar(args)

and then use foo in an expression. That pretty much rules out
solutions using partial IMO. (Not that I mind -- I find examples using
partial as hard to read as code using reduce()... :-)

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list