Steps to reproduce
Execute this program:
import box
import pickle
class MyBox(box.Box):
...
b_in = MyBox()
b_in.a = dict()
print("in root: %s" % type(b_in))
print("in .a: %s" % type(b_in.a))
p = pickle.dumps(b_in, protocol=pickle.HIGHEST_PROTOCOL)
b_out = pickle.loads(p)
print("out root: %s" % type(b_out))
print("out .a: %s" % type(b_out.a))
Expected behavior
Output:
in root: <class '__main__.MyBox'>
in .a: <class '__main__.MyBox'>
out root: <class '__main__.MyBox'>
out .a: <class '__main__.MyBox'>
Actual behavior
Output:
in root: <class '__main__.MyBox'>
in .a: <class '__main__.MyBox'>
out root: <class '__main__.MyBox'>
out .a: <class 'box.box.Box'>
i.e., the type of key a is box.box.Box when it should be __main__.MyBox.
Comments
-
I believe the problem lies in this line:
|
"box_class": box_class if box_class is not None else Box, |
where Box should insted be cls.
-
Instantiating b_in with box_class=MyBox does not help, I assume because there is something about class instantiation I don’t understand. However it did seem like it should work.
-
This does, however, work around the bug:
class MyBox(box.Box):
def __new__(cls, *args, **kwargs):
kwargs["box_class"] = MyBox
return super().__new__(cls, *args, **kwargs)
Steps to reproduce
Execute this program:
Expected behavior
Output:
Actual behavior
Output:
i.e., the type of key
aisbox.box.Boxwhen it should be__main__.MyBox.Comments
I believe the problem lies in this line:
Box/box/box.py
Line 236 in a4c10e9
where
Boxshould insted becls.Instantiating
b_inwithbox_class=MyBoxdoes not help, I assume because there is something about class instantiation I don’t understand. However it did seem like it should work.This does, however, work around the bug: