[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

It would be nice if exception pickling was more friendly to subclasses.  
Perhaps, the default should be to store and restore all state including args 
and a __dict__ if any.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution: not a bug -> 
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Pickling customized subclasses can be tricky.  The essential details are here:  
https://docs.python.org/3/library/pickle.html#object.__reduce__

Here's some code to get you started.

class ExcA(Exception):
def __init__(self, want):
msg = "missing "
msg += want
super().__init__(msg)
def __reduce__(self):
return (type(self), self.args, self.args)
def __setstate__(self, state):
self.args = stat

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Irit Katriel


Irit Katriel  added the comment:

The default __reduce__ method of Exception returns the arg you pass to the 
Exception constructor:

>>> a = ExcA("a banana")
>>> a.__reduce__()
(, ('missing a banana',))
>>> 


This is then pickled, and when unpickled the arg is passed to the ExcA 
constructor. 

If you want to change this, you can implement __reduce__ on ExcA o return just 
the part you want it to return.

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Chen Zero


Change by Chen Zero :


--
title: Python exception object is different after pickle.loads and pickle.dumps 
-> Python exception object is different after pickle.dumps and pickle.loads

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com