This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients pitrou, rhettinger, serhiy.storchaka
Date 2013-10-21.14:02:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382364174.9.0.836332683158.issue19332@psf.upfronthosting.co.za>
In-reply-to
Content
Currently dict iterating is guarded against changing dict's size. However when dict changed during iteration so that it's size left unchanged, this modification left unnoticed.

>>> d = dict.fromkeys('abcd')
>>> for i in d:
...     print(i)
...     d[i + 'x'] = None
...     del d[i]
... 
d
a
dx
dxx
ax
c
b

In general iterating over mutating dict considered logical error. It is good detect it as early as possible.

The proposed patch introduces a counter which changed every time when added or removed key. If an iterator detects that this counter is changed, it raises runtime error.
History
Date User Action Args
2013-10-21 14:02:54serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, pitrou
2013-10-21 14:02:54serhiy.storchakasetmessageid: <1382364174.9.0.836332683158.issue19332@psf.upfronthosting.co.za>
2013-10-21 14:02:54serhiy.storchakalinkissue19332 messages
2013-10-21 14:02:54serhiy.storchakacreate