[Python-Dev] Proposed tweaks to functools.wraps

Nick Coghlan ncoghlan at gmail.com
Wed Aug 11 06:43:40 CEST 2010


On Wed, Aug 11, 2010 at 1: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.

Making the parameterised decorator a callable rather than a function
can sometimes help, provided there are only a few parameters actually
needed in the wrapper function.

Making parameterised decorators easier to parse mentally was pointed
out [1] as a possible benefit of pursuing PEP 3150 (statement local
namespaces). That PEP as a whole is still sitting in "not enough
practical benefit to justify the pain" territory though.

Cheers,
Nick.

[1]  http://mail.python.org/pipermail/python-ideas/2010-July/007691.html

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list