Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'argument': 0.04; 'interpreter': 0.04; '(python': 0.05; '(especially': 0.07; 'python': 0.09; 'deletion': 0.09; 'dict': 0.09; 'enormous': 0.09; 'errors,': 0.09; 'insertion': 0.09; 'sake': 0.09; 'subject:set': 0.09; 'typeerror:': 0.09; 'def': 0.10; "wouldn't": 0.11; 'aug': 0.13; 'all).': 0.16; 'foo(object):': 0.16; 'iterating': 0.16; 'iterator.': 0.16; 'iterators': 0.16; 'low-level': 0.16; 'set,': 0.16; 'there?': 0.16; 'unbound': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'thu,': 0.17; 'typing': 0.17; '>>>': 0.18; 'developer': 0.19; '"",': 0.22; 'header:In-Reply-To:1': 0.25; '(which': 0.26; '(most': 0.27; 'checking': 0.27; 'mix': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'shoot': 0.29; 'case,': 0.29; 'class': 0.29; "i'm": 0.29; "we're": 0.30; 'error': 0.30; 'file': 0.32; 'suggestion': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'self': 0.34; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'expensive': 0.36; 'method': 0.36; 'too': 0.36; 'enough': 0.36; 'does': 0.37; 'level': 0.37; 'why': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'tracking': 0.61; 'first': 0.61; 'between': 0.63; 'more': 0.63; 'honest': 0.75; 'low': 0.83; 'glad': 0.86; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=I1Mib2sdHVyBXCW0c0pjSifIXBgBq4uQ//nOoro+kzM=; b=tEGLkx3JTZkUDmv7wm3Y/+WF+8ee5xsD+yhHRNJRD63pai81cQxwHMoBT+C8C3noZj tM1yhkDuKBayWlSvDB69Os3PXMLMpP1pq3Jy6pfclKGa9CmYUMI2lNfbbkGaBTXPdovX yVN0WAhMeVyqRyiVNBumKvSmVUMw3Rogo+YsZIAgY5rcEkO5r90yhZsmiSYZSnPD8p5j R4J3A2t9xpS8YeB7LTpJ2nhX9G34nFkQgszgadCPFs5Qu4RtHAYCqTolzmLwlU82fTY/ xEIb+jjMgj3CipS83NXXWpDOSzGRkcf6UZkXGqkAmRGI5Nl3t+riQ11JYtc2NAqUlL+m QTdA== MIME-Version: 1.0 In-Reply-To: <502D7E17.1070103@dejaviewphoto.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> From: Ian Kelly Date: Thu, 16 Aug 2012 17:43:55 -0600 Subject: Re: set and dict iteration To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345160667 news.xs4all.nl 6884 [2001:888:2000:d::a6]:58209 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27214 On Thu, Aug 16, 2012 at 5:11 PM, Dave Angel wrote: > There's an enormous difference between type errors, which affect the low > level dispatch, and checking for whether a dict has changed and may have > invalidated the iterator. If we were really going to keep track of what > iterators are tracking a given dict or set, why stop there? Why not > check if another process has changed a file we're iterating through? Or ... How does this affect low-level dispatch (Python 2.7)? >>> class Foo(object): ... def bar(self): ... return self ... >>> Foo().bar() <__main__.Foo object at 0x00CBEAB0> >>> Foo.bar(Foo()) <__main__.Foo object at 0x00CC9390> >>> Foo.bar(object()) Traceback (most recent call last): File "", line 1, in TypeError: unbound method bar() must be called with Foo instance as first argument (got object instance instead) There is no low-level need for this TypeError -- it's purely a case of not letting the developer shoot himself in the foot. Although to be honest the interpreter doesn't give quite enough rope (to mix metaphors) in this case, and I'm glad for the sake of duck typing that they removed this particular error in Python 3. With regard to key insertion and deletion while iterating over a dict or set, though, there is just no good reason to be doing that (especially as the result is very implementation-specific), and I wouldn't mind a more complete low-level check against it as long as it's not too expensive (which is not clearly the case with the current suggestion at all).