New submission from Stefan Schwarzer:
I recently was confused whether to raise a
__getstate__ if objects of my class can't and
shouldn't be pickled. 
Terry Reedy advised I should use
I wonder if the
pickle module documention should explicitly recommend
TypeError if a class wants to say that its objects can't be pickled.
What do you think?
assignee: docs@python components: Documentation messages: 217054 nosy: docs@python, sschwarzer priority: normal severity: normal status: open title: Document recommended exception for objects that shouldn't be pickled type: enhancement versions: Python 3.5
Michael Crouch added the comment:
When pickling an object fails on line 70 of copy_reg.py, a "TypeError" is raised. However, according to section 11.1.3 of the Standard Library documentation, when an unpicklable object is passed to the dump() method the "PicklingError" exception will be raised.
components: +Library (Lib) -Documentation nosy: +Michael Crouch versions: +Python 2.7 -Python 3.5
Serhiy Storchaka added the comment:
PicklingError is raised in following cases:
Programmical Pickler error (Pickler.__init__() was not called by subclass' __init__()).
Due to protocol or implementation limitations: memoizing more than 2**32 objects, saving non-ASCII globals with protocol < 3, etc. Exception type is implementation depended. Sometimes OverflowError or struct.error can be raised instead.
When __reduce__/__reduce_ex__ returns invalid value: neither str or tuple, a tuple has wrong size, first tuple element is not a callable, first argument for __newobj__/__newobj_ex__ has no __new__ or doesn't match a type of pickled object, global lookup is failed or doesn't match pickled object, etc.
When extension code is not an integer or out of range.
Terry J. Reedy email@example.com added the comment:
2.7 docs are no longer revised
nosy: +terry.reedy resolution: -> out of date stage: -> resolved status: open -> closed