Pickle inner collections.namedtuples and function attributes - #448
Conversation
bcaa58d to
9450a7b
Compare
|
I believe that the only issue for this PR is coverage. Some cases apply to Python 3.6 where defaults are not available for |
|
Whenever you are ready for a review (on this or other of your PRs), just request me as a reviewer. |
|
I think that requires permissions, just like merging an already approved PR. The open PRs are ready to review. I am still refactoring the draft and adding test cases, but it is functional. |
|
Looking back on it, I think that this PR might be a little incomplete. I think that I need to ensure that every slot defined under "User-defined functions" on https://docs.python.org/3/reference/datamodel.html gets copied over when it isn't already the default value. |
|
This PR seems to be backwards incompatible for PyPy 2.7. A function pickled in this PR will be unable to be unpickled in dill 0.3.4 on PyPy 2.7, but will be able to be unpickled on all other versions. Should there be a setting to turn off this feature to allow for the creation of backwards compatible pickles? |
Ouch. No. The good thing is that it's only for PyPy 2.7. I'll have to have a look and see if there's any way to avoid the incompatibility. |
|
There is an easy way. Instead of using This actually seems like an incredibly viable solution. After looking into it a bit more, the only two attributes for functions that are not available in the constructor for Python 2.7 are
|
__kwdefaults__ and __annotations__ are invalid in PyPy2.7
|
What's done with python 2.7 doesn't matter too much. I will be dropping support for 2.7 immediately after the next release. With regard to what to do, I'd rather not lose functionality from one release to the next -- and would much prefer living with a small hit on the time it takes to pickle something in 2.7. So, yes, the overhead of a The basic rule is don't remove functionality. |
|
Got it. |
9e81df5 to
251028f
Compare
251028f to
756d243
Compare
|
There's an issue if the |
|
Good catch. I guess I forgot to copy that code from the merge commit. |
2c1e527 to
b22ddb5
Compare
collections.namedtuplesubclassescollections.namedtuplewhen__qualname__is not__name___create_function(supersedes Pickle function attributes #422)collections.namedtupleclassesI think it is worth debating if this is the best way to handle new attributes to the function class. Some functions have
__annotations__but not__kwdefaults__. In the future, if these new attributes don't scale well, the current solution of adding them to_create_functioncould likely lead to a mess. On the other hand, these new strings would be added to all pickles whose functions that use said attributes. When many functions are pickled in one pickle, this overhead is constant. However, when pickling many functions in separate pickles, the overhead becomes linear in the number of functions. This cost should be considered.This PR also adds a breaking change. Previously,
_create_namedtupledid not save and use the default values of the tuple. In order to add the argument to this function to support it, pickling acollections.namedtuplewith default values using this PR and trying to unpickle it in an older version of dill will fail.Fixes #288, Fixes #420