-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Importing dill changes the python pickler behavior #661
Comments
This is the intended behavior. It's partially due to historical choices with python 2.x, where just by an
|
This is an incredibly unfortunate default and I think it should be reconsidered. As a user I do not control the behavior of third party libraries (dill and otherwise). I may have neither a direct dependency on dill or pickle and be bitten by this behavior. Consider the following:
|
I agree it's an unfortunate default. We looked at the impact of changing a poor decision made over a decade ago in a different ecosystem, and it'd also be very disruptive to reverse it. Hence, the addition of the "extend" function, even it has an unfortunate default. |
This behavior in dill breaks our software, despite our software not using dill. We get dill transitively imported in some applications but not others depending on whether another third party library depends on it. Given it seems this behavior won't be changed in dill, the only path forward for users in my position is to try and convince other library authors to avoid using dill themselves? |
Thoughts on something like the following in try:
import dill_noextend
except ImportError:
extend() I thought about an environment variable, but I think the above is more desirable, since it allows users to make the decision once at environment creation time. |
That's an interesting idea. I don't understand your particular case, so maybe that would help as well In general, importing Some thought needs to go into what the impact of a dependency-based global switch is. While it would seem that the right thing to do in the abstract is to not extend the registry by default... an even better solution is to not extend the pickle registry at all (unfortunately, that's not feasible). Practically, regardless of what you do when |
The scenario is something like this:
This results in a scenario where sometimes dill is imported and sometimes it is not, which changes the pickle output between scripts. I don't want to import dill and unregister in the component that uses So my options are vaguely:
None of those are very great - especially the last, since I really don't want to continue propagating the python antipattern of "try to import some thing and silently swallow the exception if it isn't there" within our codebase since it is already a great source of pain. A better option for us would be to disable this behavior in dill outright. The existence of an empty file in our python environment called and now for something completely different I'm not really sure why this default cannot be changed - it already seems to be not functioning as intended? import io
import pickle
from collections import namedtuple
SomeTuple = namedtuple('SomeTuple', 'a b')
thing = SomeTuple(1, 2)
f = io.BytesIO()
pickle._Pickler(f).dump(thing)
before_dill = f.getvalue()
import dill
f = io.BytesIO()
pickle.Pickler(f).dump(thing)
after_dill_native = f.getvalue()
assert before_dill == after_dill_native
f = io.BytesIO()
pickle._Pickler(f).dump(thing)
after_dill_python = f.getvalue()
assert before_dill != after_dill_python dill only extends the pure-python pickler, not the native pickler implementation, which is contrary to how this is described in the docs. Given that you have to go very much out of your way to use the python pickle implementation, and most people will have the native implementation, I can't imagine very many people are relying on this extend behavior anymore. |
I believe all serialization packages, Auto-extending the registry originated in python 2.x, and has never extended the native registry. When python switched |
The following shows the issue pretty clearly.
Dill is somehow not actually taking a copy of the pickler dispatch table - despite attempting to.
The text was updated successfully, but these errors were encountered: