[Python-ideas] Multiple arguments for decorators

Chris Angelico rosuav at gmail.com
Mon Nov 30 23:38:26 EST 2015


On Tue, Dec 1, 2015 at 3:30 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> 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.
>

Which I don't really like. It makes sense for generator expressions,
but list comprehensions don't *look* like they introduce a new
sub-scope. A 'with' block does look like it creates a new scope, but
its binding leaks out (usually giving you a closed file object or
something). Sure, I can understand why things are the way they are,
but it's not intuitive. You have to dig into things a bit to grok it.

> 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.
>

Agreed. And while I called the class-based system "ugly" to start
with, I'm coming around to it more and more - especially since it
works in current versions of Python, rather than demanding core
interpreter changes. It's not the most intuitive use of syntax either
(the 'class' block isn't really creating a class at all - it creates a
function parameter list), but it isn't as bad as I thought it was.

ChrisA


More information about the Python-ideas mailing list