-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
bpo-36452: dictiter: track maximum iteration count #12596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
With Python 3.8.0a4+, we get the following RuntimeError in Fedora: PYTHONPATH=../../lib ../bin/dump_keywords.py --template-dir=../templates --output-dir=rst/reference_appendices/ -d ./keyword_desc.yml Traceback (most recent call last): File "../bin/dump_keywords.py", line 49, in <module> for a in oblist[name]: RuntimeError: dictionary keys changed during iteration And: def populate(self): super(Interfaces, self).populate() self.facts['all_ipv4_addresses'] = list() self.facts['all_ipv6_addresses'] = list() data = self.responses[0] interfaces = self.parse_interfaces(data) > for key in interfaces.keys(): E RuntimeError: dictionary keys changed during iteration In TestDellos9Facts.test_dellos9_facts_gather_subset_default and TestDellos9Facts.test_dellos9_facts_gather_subset_interfaces. Python change: python/cpython#12596 Downstream bug: https://bugzilla.redhat.com/show_bug.cgi?id=1712531
Python 3.8 tracks if any key names change while iterating. python/cpython#12596
Python 3.8 tracks if any key names change while iterating. python/cpython#12596
Python now throws a RuntimeError if dict keys are modified mid-iteration. python/cpython#12596 Cast filter dicts to list before iteration. Fixes: 65024 Related: 65434
Python 3.8 tracks if any key names change while iterating. python/cpython#12596
Using: Python 3.8 (git commit ID: d5a5a33), the following code snippet:
Prints the following output:
The reason for this seems to be the way the internal key list is managed and the "next" value in this list is retrieved. The amount of items seems to be related to
USABLE_FRACTION(PyDict_MINSIZE)
.Since cases where the dictionary size changes are detected with a
RuntimeError
, I would expect the invariant "the number of iterations is the len() of the dict at the time the iterator is created" to be enforced. Whether to raise a StopIteration instead or raising a RuntimeError is up for debate.This pull request tries to detect this corner case and raise a
RuntimeError
instead (plus a unit test).Note also that without the patch, the
__length_hint__()
of the iterator actually underflows:Which - on an AMD64 machine - prints:
https://bugs.python.org/issue36452