Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17570 > unrolled thread

Re: Grammar for classes

Started byRobert Kern <robert.kern@gmail.com>
First post2011-12-20 10:55 +0000
Last post2011-12-20 10:55 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Grammar for classes Robert Kern <robert.kern@gmail.com> - 2011-12-20 10:55 +0000

#17570 — Re: Grammar for classes

FromRobert Kern <robert.kern@gmail.com>
Date2011-12-20 10:55 +0000
SubjectRe: Grammar for classes
Message-ID<mailman.3859.1324378559.27778.python-list@python.org>
On 12/20/11 1:34 AM, Joshua Landau wrote:
> In reading thorough the syntax defined in the reference
> <http://docs.python.org/py3k/reference/compound_stmts.html#class-definitions>,
> 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?

I suspect that it's harder to make a grammar rule that allows every kind of 
expression except for generator expressions than it is just to reuse the 
"testlist" rule and let the runtime reject the generator object when it goes to 
construct the class.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web