Grammar for classes

Ian Kelly ian.g.kelly at gmail.com
Mon Dec 19 22:46:29 EST 2011


On Mon, Dec 19, 2011 at 6:34 PM, Joshua Landau
<joshua.landau.ws at gmail.com> wrote:
> In reading thorough the syntax defined in the reference, the class statement
> has surprised me.
>
> It says that the inheritance part of the class can accept comprehensions.
> What does this mean?
> I've tried:
> "class A(x for x in ()): pass"
> but this doesn't need the extra clause as "x for x in ()" is an expression,
> and thus this evaluates:
> "class A(x for x in (),): pass"
> although again it won't be a valid class anytime soon.
>
> So what is this clause for?

That's new to me as well.  There's nothing about it in PEP 3115.  I
suspect it's a bad copy-and-paste from the function call syntax.



More information about the Python-list mailing list