When adding new key, dk_usable is decremented. When removing key, dk_usable is not decremented. So I think dk_usable & ma_used pair can be used to detect dict size modification. On Wed, Dec 14, 2016 at 8:02 AM, Serhiy Storchaka <storchaka at gmail.com> wrote: > On 13.12.16 11:51, Max Moroz 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? >> >> Currently, dict.__iter__ only raises "RuntimeError" when "dictionary >> changed size during iteration". I managed to add 1 key and delete 1 >> key from the dictionary in the same iteration of the loop (the code >> was in a callback function invoked in the loop) - of course without >> any exception. (I hope I'm right in assuming that adding and deleting >> entries in the loop is unsafe whether or not number of adds equals >> number of deletes.) >> >> I suspect the cost of a more comprehensive error reporting is not >> worth the benefit, but I thought I'd ask anyway. > > > The patch implementing this was rejected. > > http://bugs.python.org/issue19332 > > > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/songofacandy%40gmail.com -- INADA Naoki <songofacandy at gmail.com>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4