Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; "'''": 0.09; 'behave': 0.09; 'defined.': 0.09; 'docs.': 0.09; 'iterate': 0.09; 'subject:set': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'static': 0.13; 'modification': 0.15; '"by': 0.16; 'code?': 0.16; 'defined;': 0.16; 'enough.': 0.16; 'entries.': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'runtimeerror': 0.16; 'later': 0.16; 'wrote:': 0.17; 'comparing': 0.17; 'detect': 0.17; 'element': 0.17; 'url:dev': 0.17; 'error.': 0.21; 'not,': 0.21; 'regardless': 0.21; 'bug?': 0.22; 'doc': 0.22; "user's": 0.22; 'cc:2**0': 0.23; 'sets': 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'continuing': 0.27; 'entries': 0.27; 'set.': 0.27; 'behavior.': 0.29; 'dictionary': 0.29; 'hash': 0.29; 'problem.': 0.32; 'url:python': 0.32; 'structure': 0.32; 'another': 0.33; 'clear': 0.35; 'fail': 0.35; 'pm,': 0.35; "won't": 0.35; 'add': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'received:192': 0.39; 'hello,': 0.39; 'received:192.168': 0.40; 'skip:u 10': 0.60; 'remove': 0.61; 'between': 0.63; 'behavior': 0.64; 'therefore': 0.65; 'header:Reply-To:1': 0.68; 'protect': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'forced': 0.84; 'observed': 0.84; 'received:74.208.4.194': 0.84 Date: Thu, 16 Aug 2012 15:49:39 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Aaron Brady Subject: Re: set and dict iteration References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:FgHWooMGWb7PsIcjrOShJzB/vBslzXZRfDyl7LSpOP9 0sjgNsWuOXtKylRcxxqqLkQKe6xVIyGR9UcGlaWTYUWXycc8UA LvLJT3ydf8p0O4CaRCKrDiycO18lcjFKPvF8pp3hg6L3o3PTr7 0TIN1O97MPsz1Vptfws2aWzWHq02hGlZk4qdXhXjWTw2w8dqoP WthYq3k3PTuUTN/gCXLqt+/cdRYDsh2KEyvqCzFQqlT0fAGNWQ jblIJO29BymmCmxSk7f0m3qGHPVrgNyJGUx731GqWOBVX1RZt9 h95ll8axoKnoa+UTsX6PyEYHQTHyax9TPz/kaXsu+repxuXCg= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 1345146609 news.xs4all.nl 6987 [2001:888:2000:d::a6]:45330 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27195 On 08/16/2012 02:00 PM, Aaron Brady wrote: > Hello, > > I observed an inconsistency in the behavior of 'set' and 'dict' iterators. It is "by design" according to the docs. > > ''' > http://docs.python.org/dev/library/stdtypes.html#dict-views > > iter(dictview). Iterating views while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries. > ''' > > The 'set' has the same behavior. Iteration might also complete successfully. > > The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: > > > > Iteration should behave the same regardless of the contents of the set. Continuing iteration over sets and dicts after a modification isn't defined; it should unconditionally raise an error. Why is it the iterator's job to protect against the user's bug? The doc is clear enough. If you don't change the collection, you won't have a problem. > . Everything else is implementation defined. Why should an implementation be forced to have ANY extra data structure to detect a static bug in the caller's code? -- DaveA