Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder5.xlned.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'python.': 0.04; 'mentioned,': 0.04; 'value,': 0.04; '*not*': 0.05; 'attributes': 0.05; 'cpython': 0.05; 'attribute': 0.07; 'names.': 0.07; 'terry': 0.07; 'python': 0.08; '>>>>': 0.09; 'attributes,': 0.09; 'ironpython': 0.09; 'mutable': 0.09; 'namespace': 0.09; 'cc:addr:python-list': 0.15; 'syntax': 0.15; 'identifiers': 0.16; 'metaclass': 0.16; 'names?': 0.16; 'patently': 0.16; 'received:209.85.210.42': 0.16; 'received:mail- pz0-f42.google.com': 0.16; 'reedy': 0.16; 'subject:() ': 0.16; 'tangent,': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.18; '>>>': 0.18; '(most': 0.21; 'trying': 0.21; 'cc:no real name:2**0': 0.21; "aren't": 0.21; '(or': 0.22; "doesn't": 0.23; 'breaks': 0.23; 'documented': 0.23; 'equally': 0.23; 'though.': 0.23; 'header:In-Reply-To:1': 0.23; 'traceback': 0.24; 'cc:2**0': 0.25; 'fact': 0.27; 'classes': 0.27; 'not.': 0.27; 'url:mailman': 0.27; 'language.': 0.28; 'invalid': 0.28; 'generic': 0.28; 'cc:addr:python.org': 0.29; 'message- id:@mail.gmail.com': 0.29; 'class': 0.29; 'typeerror:': 0.30; 'example': 0.30; 'equivalent': 0.30; 'subject:?': 0.31; 'error': 0.31; 'least': 0.31; 'nov': 0.31; 'pm,': 0.31; 'cases': 0.32; 'implementing': 0.32; 'thu,': 0.32; 'error.': 0.32; 'url:listinfo': 0.32; 'does': 0.32; "can't": 0.32; 'actually': 0.33; 'there': 0.33; 'calling': 0.33; 'done': 0.33; 'implies': 0.34; 'last):': 0.34; 'state:': 0.34; "what's": 0.35; 'url:python': 0.35; 'something': 0.36; '...': 0.36; 'fri,': 0.36; 'another': 0.36; 'but': 0.37; 'think': 0.37; 'two': 0.37; 'steven': 0.38; 'guys': 0.38; 'received:google.com': 0.38; 'else': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'e.g.': 0.38; 'should': 0.39; 'why': 0.39; 'subject:: ': 0.39; 'perform': 0.39; 'received:209': 0.40; 'user': 0.40; 'really': 0.40; 'your': 0.61; '2011': 0.62; '11,': 0.68; 'truth': 0.68; 'legal': 0.71; 'promise': 0.71; 'validation': 0.73; '-0500,': 0.84; 'untrue.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=J2ZufxBybcrD+8ROZKet0SpmbcojSoB672d5snAyKGM=; b=KftDHCbu6WUvECDBomMsk6620P9qYQsWopeSVoCgTRLGgPemCixMm27vbcTEL8Ble5 baP0oV7p1JC/ZLL0MMPOPE/NmbmGcu6+RsuVtrSBkarOZZAWLeXGP7e10eN7bVPb/C1r sqm4m7iHsbNklchCOzf1qBa9gPSHtNt18JUCQ= MIME-Version: 1.0 In-Reply-To: <4ebdc961$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <436fb6a3-1075-45a6-8f93-5612d050b11a@q35g2000prh.googlegroups.com> <4eb9e9c2$0$29988$c3e8da3$5496439d@news.astraweb.com> <4ebb08b6$0$29970$c3e8da3$5496439d@news.astraweb.com> <4EBC1B54.6000308@stoneleaf.us> <4ebc592b$0$29970$c3e8da3$5496439d@news.astraweb.com> <4ebdc961$0$29970$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Sun, 13 Nov 2011 01:28:31 -0500 Subject: Re: all() is slow? To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321165756 news.xs4all.nl 6867 [2001:888:2000:d::a6]:47972 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15635 > which implies that getattr(x, 'a!b') should be equivalent to x.a!b No, it does not. The documentation states equivalence for two particular values, and there is no way to deduce truth for all cases from that. In fact, if it _was_ trying to say it was true for any attribute value, then your example would be proof that the documentation is incorrect, since CPython breaks that equivalence. Devin On Fri, Nov 11, 2011 at 8:18 PM, Steven D'Aprano wrote: > On Thu, 10 Nov 2011 23:35:32 -0500, Devin Jeanpierre wrote: > >>> That is patently untrue. If you were implementing namedtuple without >>> exec, you would still (or at least you *should*) prevent the user from >>> passing invalid identifiers as attribute names. What's the point of >>> allowing attribute names you can't actually *use* as attribute names? >> >> Then why doesn't Python do this anywhere else? e.g. why can I >> setattr(obj, 'a#b') when obj is any other mutable type? > > That is implementation-specific behaviour and not documented behaviour > for Python. If you try it in (say) IronPython or Jython, you may or may > not see the same behaviour. > > The docs for getattr state: > > =C2=A0 =C2=A0getattr(x, 'foobar') is equivalent to x.foobar > > > which implies that getattr(x, 'a!b') should be equivalent to x.a!b which > will give a syntax error. The fact that CPython does less validation is > arguably a bug and not something that you should rely on: it is *not* a > promise of the language. > > As Terry Reedy already mentioned, the namespace used in classes and > instances are ordinary generic dicts, which don't perform any name > validation. That's done for speed. Other implementations may use > namespaces that enforce legal names for attributes, and __slots__ already > does: > >>>> class X(object): > ... =C2=A0 =C2=A0 __slots__ =3D ['a', 'b!'] > ... > Traceback (most recent call last): > =C2=A0File "", line 1, in > TypeError: Error when calling the metaclass bases > =C2=A0 =C2=A0__slots__ must be identifiers > > > [...] >> To go off on another tangent, though, I don't really understand how you >> guys can think this is reasonable, though. I don't get this philosophy >> of restricting inputs that would otherwise be perfectly valid > > But they aren't perfectly valid. They are invalid inputs. Just because > getattr and setattr in CPython allow you to create attributes with > invalid names doesn't mean that everything else should be equally as > slack. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list >