Irit Katriel <[email protected]> added the comment:
> I want to known why it is
It's because Exception implements __reduce__ and that takes precedence over
__getnewargs_ex__. You can see that with this example:
""""
import pickle
class MyException():
def __init__(self, desc, item):
super().__init__()
self.desc = desc
self.item = item
def __getnewargs_ex__(self):
print('called in {}.__getnewargs_ex__'.format(self.__class__.__name__))
return (self.desc,), self.__dict__
def __reduce__(self):
print('called in {}.__reduce__'.format(self.__class__.__name__))
return MyException, (self.desc, self.item),
e = MyException('testing', item='cpu')
s = pickle.dumps(e, protocol=-1)
x = pickle.loads(s)
""""
Output: called in MyException.__reduce__
----------
nosy: +iritkatriel
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37489>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com