← 输入框|bugs.python.org|刷新

➜

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.

作者 serhiy.storchaka
收信人 pitrou, rhettinger, serhiy.storchaka
日期 2013-10-21.14:02:54
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1382364174.9.0.836332683158.issue19332@psf.upfronthosting.co.za>
In-reply-to
内容
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.
历史
日期 用户 动作 参数
2013-10-21 14:02:54serhiy.storchaka修改recipients: + serhiy.storchaka, rhettinger, pitrou
2013-10-21 14:02:54serhiy.storchaka修改messageid: <1382364174.9.0.836332683158.issue19332@psf.upfronthosting.co.za>
2013-10-21 14:02:54serhiy.storchaka链接issue19332 messages
2013-10-21 14:02:54serhiy.storchaka创建