-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-35900: Enable custom reduction callback registration in _pickle #12499
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a batch of comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a quick review. Summary:
- the same hook needs to be available (and tested) on the pure Python implementation as well
- the hook should be able to be specified as a method in a subclass, as well as an independent callable (therefore its signature should be just
(obj)
, IMHO) - some docs need to be added
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@ncoghlan What do you think about the name |
@pitrou The proposed method name seems fine to me, but I'd expect to see a docs update to https://docs.python.org/3/library/pickle.html#pickle.Pickler to mention the subclassing API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks for making the requested changes! @pitrou: please review the changes made to this pull request. |
Co-Authored-By: pierreglaser <pierreglaser@msn.com>
0782079
to
2de069e
Compare
Rebased. |
- Some readibility changes
The C implementation of the
Pickler
class does not allow to register custom pickling behavior for classes and functions.This PR enables it by adding a hook that will call a user-defined callable for those types. If no callable is registered, then the
pickler
simply fallbacks thesave_global
method, as before.See also:
cloudpipe/cloudpickle#253
https://bugs.python.org/issue35900