Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '<>,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'runtime': 0.09; 'underlying': 0.09; 'am,': 0.12; 'enigma': 0.16; 'expression,': 0.16; 'kern': 0.16; 'subject:classes': 0.16; 'tried:': 0.16; 'syntax': 0.16; 'wrote:': 0.18; 'thorough': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'statement': 0.23; 'thus': 0.23; 'clause': 0.23; 'defined': 0.24; 'suspect': 0.24; 'says': 0.25; 'expressions': 0.29; 'interpret': 0.29; 'class': 0.29; 'construct': 0.30; "i've": 0.31; 'does': 0.32; "won't": 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'object': 0.33; 'to:addr:python-list': 0.34; 'rule': 0.34; 'surprised': 0.34; 'url:python': 0.36; 'class.': 0.37; 'for?': 0.37; 'but': 0.37; 'except': 0.37; 'reference': 0.37; 'received:org': 0.38; 'allows': 0.38; 'url:docs': 0.39; 'url:org': 0.39; 'goes': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'kind': 0.61; 'world': 0.62; 'our': 0.64; 'harder': 0.64; 'believe': 0.65; 'soon.': 0.71; 'anytime': 0.74; 'received:109': 0.78; 'url:reference': 0.84; 'eco': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Grammar for classes Date: Tue, 20 Dec 2011 10:55:41 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host109-153-163-100.range109-153.btcentralplus.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324378559 news.xs4all.nl 6935 [2001:888:2000:d::a6]:43030 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17570 On 12/20/11 1:34 AM, Joshua Landau 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? 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