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
OrderedDict iterators are exhausted during pickling #78755
Comments
In [1]: from collections import OrderedDict In [2]: od = OrderedDict.fromkeys(range(10)) In [3]: it = iter(od) In [4]: it.__reduce__() In [5]: list(it) |
This would presumably be a side-effect of all generic pickling operations of iterators; figuring out what the iterator produces requires running out the iterator. You could special case it case-by-case, but that just makes the behavior unreliable/confusing; now some iterators pickle without being mutated, and others don't. Do you have a proposal to fix it? Is it something that needs to be fixed at all, when the option to pickle the original OrderedDict directly is there? |
Other iterators either don't support pickling or aren't mutated during pickling: In [10]: it = iter({1}) In [11]: pickle.dumps(it) In [12]: list(it) In [13]: it = (x for x in {1}) In [14]: pickle.dumps(it) TypeError Traceback (most recent call last)
<ipython-input-14-7e86a183a31c> in <module>()
----> 1 pickle.dumps(it) TypeError: can't pickle generator objects |
Thank your Sergey for your report and fix. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: