[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

[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 mailin

[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 ___ ___ Pyt

[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 = "missin

[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.

[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 ___