-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Inconsistent restoration of types and class overwriting side effects #512
Comments
The
|
Yeah, I have to agree. The
So, there's potential in using the settings to control the desired |
It's here: Lines 1238 to 1241 in 13e3f80
|
I guess that named tuple is fine then. What should have happened is that the check to see if the named tuple was accessible should have been done in Nope. It still seems that Line 2067 in 13e3f80
|
@leogama: A while ago, I posed the same question, and I think the answer is that it is probably a useful thing to do. See: #90, #102, and #128. We should think about changing |
This is not strictly a bug, but may not be the expected behavior. There are 3 possibilities when unpickling a type object (here named "
atype
"):atype.__name__
in the moduleatype.__module__
*;atype
.atype
.(*) or the module can't be found, or the type object has no
__module__
attribute, likeenum
s andnamedtuple
s can be.The first and second cases should be straightforward to deal with by just creating or overwriting the class, respectively. In the third case, I think it's open for debate which solutions make more sense in different situations. The issue is that dill currently doesn't have a single orientation in this regard, with mixed outcomes.
The example below is based on the last commit from #450 and includes an
Enum
, anamedtuple
—and I don't know ifdataclass
is another special case—, a custom class that doesn't check the objects' classes when testing for equality and a custom class that does it.class_demo.py
The code below shows what happens when comparing "identical" objects created before and after the state of the module containing its classes is saved and restored.
Output:
Therefore, as of today dill always prefer the existing
namedtuple
type definition, even if the one being unpickled is different. On the other hand, it always prefer the unpickled type object in all other cases, overwriting the existing one even if they are identical (in the sense that they would generate identical pickle streams), which may or may not affect operations between instances of different versions of the same class.I would prefer not to think about this kind of stuff, but I'm unable to concentrate in anything else before I write it down and share with you...
The text was updated successfully, but these errors were encountered: