You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When pickling a complex object, or a graph of objects, it is difficult to locate the source of error. At best you get the type of the unpickleable object at the bottom level, but you cannot know the part of what object or data structure it is.
The proposed PR adds notes to the raised exception which allow to identify the source of the error. For example:
>>> import pickle
>>> pickle.dumps([{'a': 1, 'b': 2}, {'a': 3, 'b': pickle}])
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
pickle.dumps([{'a': 1, 'b': 2}, {'a': 3, 'b': pickle}])
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot pickle 'module' object
when serializing dict item 'b'
when serializing list item 1
>>> classA: pass
...
>>> a = A()
>>> a.x = pickle
>>> pickle.dumps(a)
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
pickle.dumps(a)
~~~~~~~~~~~~^^^
TypeError: cannot pickle 'module' object
when serializing dict item 'x'
when serializing A state
Feature or enhancement
When pickling a complex object, or a graph of objects, it is difficult to locate the source of error. At best you get the type of the unpickleable object at the bottom level, but you cannot know the part of what object or data structure it is.
The proposed PR adds notes to the raised exception which allow to identify the source of the error. For example:
See also similar issue #122163 for JSON.
Linked PRs
The text was updated successfully, but these errors were encountered: