Skip to content
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

Dill Should Use a Custom dispatch_table vs Modifying pickle._Pickler.dispatch #456

Open
elmq0022 opened this issue Feb 28, 2022 · 1 comment

Comments

@elmq0022
Copy link

Dill modifies python's pickler._Pickle.dispatch. This means it can clash with similar packages with similar goals, notably cloudpickle.

Dill does provide dill.extend to turn dill on and off, but this is cumbersome and relies on the user to be know when dill is or is not enabled.

Using a custom dispatch_table as specified in the Python's pickle documentation would be a cleaner implementation, in my opinion, as dill's extensions would be scoped only to dill and not clash with other packages polluting the global scope.

I haven't scoped the effort required, but I would be willing to assist if the maintainer(s) are willing to entertain such a change.

@mmckerns
Copy link
Member

mmckerns commented Mar 1, 2022

dill made the choice to modify the contents of the pickle dispatch table, and unfortunately, cloudpickle made the same choice years later. So, yes, this causes potential clashes. One of the reasons this choice was made is historical, in that in python 2.x, pickle used a python dispatch table (and a pure python pickler) -- so, just by importing dill, one could augment the serialization of a package that is built to use pickle. In python 3.x, pickle uses a C pickler, so the augment of the _Pickle dispatch table is less impactful. Feel free to explore a PR along the lines you suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants