Problem with OrderedDict - progress report

INADA Naoki songofacandy at gmail.com
Fri Jun 1 04:02:46 EDT 2018


On Fri, Jun 1, 2018 at 4:56 PM Gregory Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Chris Angelico wrote:
> > It is an error to mutate the dictionary *and then continue to iterate
> over it*.
>
> But if you're processing the last key, and you add one so
> that it's no longer the last key, what should happen?
>
> My feeling is that this should be an error, because it's
> not clear whether iteration should stop at that point
> or not.
>
> --
> Greg
> --
> https://mail.python.org/mailman/listinfo/python-list
>

​Regardless how CPython works, it's prohibited, and behavior is
**undefined**.​
There are no "what should happen".

Python interpreters may or may not raise error.  And any error
(RuntimeError,
MemoryError, interpreter freeze) may happen.

Python programmer shouldn't rely on the behavior.

​Regards,​

-- 
INADA Naoki  <songofacandy at gmail.com>



More information about the Python-list mailing list