[Python-Dev] Making sure dictionary adds/deletes during iteration always raise exception

Ronald Oussoren ronaldoussoren at me.com
Tue Dec 13 12:04:55 EST 2016


> On 13 Dec 2016, at 17:52, Eric V. Smith <eric at trueblade.com> wrote:
> 
> 
>> On Dec 13, 2016, at 11:42 AM, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
>> 
>> 
>>> On Dec 13, 2016, at 1:51 AM, Max Moroz <maxmoroz at gmail.com> wrote:
>>> 
>>> Would it be worth ensuring that an exception is ALWAYS raised if a key
>>> is added to or deleted from a dictionary during iteration?
>>> <snip>
>>> I suspect the cost of a more comprehensive error reporting is not
>>> worth the benefit, but I thought I'd ask anyway.
>> 
>> I think what we have has proven itself to be good enough to detect the common cases, and it isn't worth it to have dicts grow an extra field which has to be checked or updated on every operation.
>> 
> 
> I agree that we shouldn't complicate things, but wouldn't PEP 509 be a cheap way to check this?

Doesn’t that update the version with every change to a dict instance? That is, not just when the set of keys for the dict changes.

Ronald



More information about the Python-Dev mailing list