Message200784
| 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:54 | serhiy.storchaka | set | recipients: + serhiy.storchaka, rhettinger, pitrou |
| 2013-10-21 14:02:54 | serhiy.storchaka | set | messageid: <1382364174.9.0.836332683158.issue19332@psf.upfronthosting.co.za> |
| 2013-10-21 14:02:54 | serhiy.storchaka | link | issue19332 messages |
| 2013-10-21 14:02:54 | serhiy.storchaka | create | |