Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-07 Thread Nick Coghlan
On 7 Nov 2013 03:18, "Antoine Pitrou" wrote: > > Le 06/11/2013 06:41, Nick Coghlan a écrit : > >> >> The behaviour of mutating builtin containers while iterating over them >> is formally undefined beyond "it won't segfault" (one of the few such >> undefined behaviours in Python). The associated ex

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Ethan Furman
Thank you, Raymond, and everyone else who responded both here and on the tracker. -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/pyt

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Serhiy Storchaka
06.11.13 21:12, Eric Snow написав(ла): Just to clarify, do you mean we should only guard against modifications to the dict's keys during its iterator's __next__()? Changes to the values during __next__() would be okay, as would changes to the keys if they happen outside __next__()? Dict iterati

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Eric Snow
On Wed, Nov 6, 2013 at 11:02 AM, Serhiy Storchaka wrote: > Actually we should guard not against changing dict during iteration, but > against iterating modifying dict (and only such modifications which change > dict's keys). s/iterating modifying/iteration modifying/ ? Just to clarify, do you me

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Serhiy Storchaka
06.11.13 07:41, Nick Coghlan написав(ла): If the benchmark suite indicates there's no measurable speed penalty then such a patch may be worth reconsidering. I don't see any significant speed difference even in artificial presumably worst case (a lot of items assignment in tight loop). If you

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Antoine Pitrou
Le 06/11/2013 06:41, Nick Coghlan a écrit : The behaviour of mutating builtin containers while iterating over them is formally undefined beyond "it won't segfault" (one of the few such undefined behaviours in Python). The associated exceptions are thus strictly "best effort given other constrain

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread R. David Murray
On Wed, 06 Nov 2013 16:10:16 +0100, Victor Stinner wrote: > More recently, I added another exception if a dictionary is modified > during a lookup. > > When I proposed a new frozendict type to secure my pysandbox project, > Armin Rigo wrote that CPython segfaults must be fixed. So I fixed a > co

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Victor Stinner
2013/11/6 R. David Murray : > On Wed, 06 Nov 2013 23:34:22 +1100, Steven D'Aprano > wrote: >> On Tue, Nov 05, 2013 at 08:38:09PM -0800, Ethan Furman wrote: >> >> > http://bugs.python.org/issue19332 >> >> Duplicate of this: http://bugs.python.org/issue6017 >> >> The conclusion on that also was tha

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread R. David Murray
On Wed, 06 Nov 2013 23:34:22 +1100, Steven D'Aprano wrote: > On Tue, Nov 05, 2013 at 08:38:09PM -0800, Ethan Furman wrote: > > > http://bugs.python.org/issue19332 > > Duplicate of this: http://bugs.python.org/issue6017 > > The conclusion on that also was that it is not worth guarding against >

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Steven D'Aprano
On Tue, Nov 05, 2013 at 08:38:09PM -0800, Ethan Furman wrote: > http://bugs.python.org/issue19332 Duplicate of this: http://bugs.python.org/issue6017 The conclusion on that also was that it is not worth guarding against such an unusual circumstance. -- Steven

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-05 Thread Eric Snow
On Nov 5, 2013 10:42 PM, "Nick Coghlan" wrote: > If the benchmark suite indicates there's no measurable speed penalty then such a patch may be worth reconsidering. I'd be astonished if that was actually the case, though - the lowest impact approach I can think of is to check for live iterators whe

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-05 Thread Nick Coghlan
On 6 Nov 2013 15:02, "Ethan Furman" wrote: > > http://bugs.python.org/issue19332 > > Summary: > > --> d = {1: 'one'} > --> for k in d: > ... d[k+1] = d[k] * k > ... > Traceback (most recent call last): > File "", line 1, in > RuntimeError: dictionary changed size during iteration > > --> for

[Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-05 Thread Ethan Furman
http://bugs.python.org/issue19332 Summary: --> d = {1: 'one'} --> for k in d: ... d[k+1] = d[k] * k ... Traceback (most recent call last): File "", line 1, in RuntimeError: dictionary changed size during iteration --> for k in d: ... del d[k] ... Traceback (most recent call last): File