-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
PEP 750: TemplateIter
is not pickleable
#133216
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
Comments
TemplateIter
is not picklebaleTemplateIter
is not pickleable
Do we need this? Compare #101588 where we deprecated support for pickling itertools iterators because it was inefficient and bug-prone. |
In my opinion, yes, because But, I am open to other opinions. |
My opinion is that unless a strong use case emerges we should say "no". Generators are the easiest and most common way to make iterators, but they cannot be pickled. That creates a strong presumption that iterators are not picklable in general. (That is why this is remarked as a possible feature rather than a bug). We do have some holdovers like str_iterator from a time where we tried to pickle everything. It is still there because there is no point in creating pain for someone who did rely on it. But it is mostly unknown and hasn't proven itself to be essential. And since strings are immutable and self-contained, there isn't much that can go wrong, so it is mostly harmless. One other thought. We should be careful with "lever arguments" in the form of "you did it once in tool A, so now you have to do it tool B". Sometimes the cost/benefit for A was that it was nearly zero cost (an easy case) and we speculated that there might be a benefit. Later when B comes along, it may be a more complex case (more complex state, mutable inputs, non-picklable inputs, etc) and have already learned that A never really paid-off. Also, we should have a principle of parsimony and be reluctant to implement possible YAGNI features. While I will stop short of saying that pickling iterators is always a bad idea. But it usually is. Mostly, nothing good with come from it. If it were really necessary, we would have long ago made generators pickeable (saving the gi_frame's locals and lineno). |
Bug report
Right now you can't pickle
string.templatelib.TemplateIter
objects. I missed it during mypickle
PR.Demo:
I think that it should be fixed. I will send a PR with code and tests soon.
The text was updated successfully, but these errors were encountered: