Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17591
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Subject | Re: Grammar for classes |
| Date | 2011-12-20 17:20 +0000 |
| References | <CAN1F8qWV1j-2VDvMyh47dxfj4G_yXSP8rcUdmpBY-HLrD5gaUQ@mail.gmail.com> <jcppjc$va7$1@dough.gmane.org> <CAN1F8qXjE0zPrUjC-Kih=gCm=pv4mwGPCvT+Y5EE3XVwVw3WwA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3871.1324401626.27778.python-list@python.org> (permalink) |
On 12/20/11 5:05 PM, Joshua Landau wrote: > On 20 December 2011 10:55, Robert Kern <robert.kern@gmail.com > <mailto:robert.kern@gmail.com>> wrote: > > 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 > <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. > > > The thing is, as far as I can tell, the grammar would be the same without the > added clause. That is because it's a valid grammar anyway. The only exception I > can think of is if generators were treated exceptionally. Thus, while I agree it > makes complete sense to make it a runtime error, the clause in the specification > seems to be fluff. > > Also - what is this "testlist" rule thee speaks of? Sorry, I was looking at the actual 2.7 Grammar file. "testlist" has been renamed to "arglist" in the 3.2 version of the Grammar, but the substantive point I made remains (to the extent that it is relevant at all). That said, the documentation for both versions differs from a simple restatement of the Grammar rules, so I'm not sure exactly why the documentation is written the way it is. -- 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Grammar for classes Robert Kern <robert.kern@gmail.com> - 2011-12-20 17:20 +0000
csiph-web