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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4