◐ Shell
clean mode source ↗

Message 287304 - Python tracker

True. Attributes __context__, __cause__ and __traceback__ are not pickled. The traceback objects are even not pickleable.

What is worse, some other non-special attributes are lost during pickling. For example name and path attributes of ImportError.

>>> try: import foo
... except Exception as ex: exc = ex
... 
>>> exc.name
'foo'
>>> exc.__reduce__()
(<class 'ModuleNotFoundError'>, ("No module named 'foo'",), {})

Or the value attribute of StopIteration if it was not passed to the constructor.

>>> exc = StopIteration()
>>> exc.value = 42
>>> exc.__reduce__()
(<class 'StopIteration'>, (), {})