[Python-ideas] Multiple arguments for decorators

Andrew Barnert abarnert at yahoo.com
Mon Nov 30 23:30:04 EST 2015


On Nov 30, 2015, at 18:58, Chris Angelico <rosuav at gmail.com> wrote:
> 
>> On Tue, Dec 1, 2015 at 1:52 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> I think this is a bad idea from the start. Only functions and classes have scopes; normal suite do not. If you change that to add "... except the suite of a with statement whose context manager is a decorator", that's no longer a simple rule you can hold in your head.
> 
> And list comprehensions.

Comprehensions define functions, so it's the same rule; you just have to know that functions can be defined three ways (def statement, lambdas expression, or comprehension) rather than just two. Sure, that's not _ideally_ simple, but that hardly seems a reason to make it even _less_ simple.

Also, comprehensions don't have a suite--you can't define arbitrary new variables or use global/nonlocal statements or anything else that would make you have to think carefully about scoping.

Most importantly, comprehensions don't have a suite that looks exactly the same as another kind of suite introduced by the same keyword that doesn't define a scope, except on this one special case where it does.



More information about the Python-ideas mailing list