Xavier Morel wrote:
On 2 Sep 2009, at 12:15 , Rob Cliffe wrote:
@Identity(DecoList[0]) # THIS WORKS def foo(): pass
For what it's worth, you don't need an id function, you can simply write
@itemgetter(0)(decorators) def foo(): 'whatever'
or
@decorators.__getitem__(0) def foo(): 'whatever'
To be honest, I'd forgotten the restriction was even there. So +0 on removing it and relying on "consenting adults" and style guides to keep people from getting to obscure with their decorators.
However, any such change should also be accompanied by an update to PEP 8 (recommending the current syntactic restrictions as style rules for the standard library).
Cheers, Nick.
On Wed, Sep 2, 2009 at 4:18 AM, Nick Coghlanncoghlan@gmail.com wrote:
Xavier Morel wrote:
On 2 Sep 2009, at 12:15 , Rob Cliffe wrote:
@Identity(DecoList[0]) # THIS WORKS def foo(): pass
For what it's worth, you don't need an id function, you can simply write
@itemgetter(0)(decorators) def foo(): 'whatever' or
@decorators.__getitem__(0) def foo(): 'whatever'
To be honest, I'd forgotten the restriction was even there. So +0 on removing it and relying on "consenting adults" and style guides to keep people from getting to obscure with their decorators.
However, any such change should also be accompanied by an update to PEP 8 (recommending the current syntactic restrictions as style rules for the standard library).
To be honest, I'm still -0 on allowing full expression syntax, but I'm fine allowing @foo[expr]. Decorators are syntactic sugar that make existing functionality more readable. I don't think that allowing complex expressions in the decorator furthers that goal.
After all the solution is always only one line away:
helper = <complicated expression> @helper def func(args): body