[Python-ideas] Mutating while iterating
Nick Coghlan
ncoghlan at gmail.com
Sun Jul 27 05:39:59 CEST 2014
On 27 July 2014 06:51, Aaron Brady <castironpi at gmail.com> wrote:
> Hi, I asked about the inconsistency of the "RuntimeError" being raised when
> mutating a container while iterating over it here [1], "set and dict
> iteration" on Aug 16, 2012.
Hi,
This is clearly an issue of grave concern to you, but as Raymond
pointed out previously, you appear to have misunderstood the purpose
of those exceptions. They're there to prevent catastrophic failure of
the interpreter itself (i.e. segmentation faults), not to help find
bugs in user code. If users want to mutate containers while they're
iterating over them, they're generally free to do so. The only time
we'll actively disallow it is when such mutation will outright *break*
the iterator, rather than merely producing potentially surprising
results.
I have closed the new issue and added a longer reply (with examples)
that will hopefully better explain why we have no intention of
changing this behaviour: http://bugs.python.org/issue22084#msg224100
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list