This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: set.__getstate__ is not overriden
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: ajaksu2, gsakkis, rhettinger, tim.peters, zseil
Priority: normal Keywords:

Created on 2005-10-14 06:38 by gsakkis, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg26594 - (view) Author: George Sakkis (gsakkis) Date: 2005-10-14 06:38
>>> import pickle
>>> class Foo(set):
...     def __getstate__(self): assert False

>>> pickle.dumps(Foo())
# doesn't raise AssertionError

The same happens with frozenset.
msg26595 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-10-14 14:37
Logged In: YES 
user_id=80475

Tim, do you have any thoughts on this?  I'm unclear on
whether this is a bug in set(), in copy_reg, in pickle, or
even a bug at all.

setobject.c implements pickling via a __reduce__() method. 
msg26596 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2006-04-01 01:37
Logged In: YES 
user_id=1326842

The problem is that __reduce__() and __reduce_ex__()
have complete control over the process of pickling.

The simple solution would be to switch to the
__getnewargs__() method for pickle protocol 2
(this is simple, __getnewargs__() should
return a tuple which is passed to the constructor
when unpickling. This means that you can reuse the
part of the current code that creates the args tuple)

For protocols 0 and 1, the following should be added
to the copy_reg module:

def pickle_set(s):
    return set, list(s)

pickle(set, pickle_set, set)

def pickle_frozenset(s):
    return frozenset, list(s)

pickle(set, pickle_set, set)


The other options are:
 - copy the semantics from object_reduce_ex
 - add support directly to pickle and cPickle
msg83881 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-20 22:59
Confirmed, but it's still not clear whether it should change.
msg83904 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-03-21 00:44
Am going to close this one.  Subclassers have the option of overriding
__reduce__ to control pickling.  My reading of the docs shows no
guarantees that builtin types won't use __reduce__.  Since this has been
out for a good while, there doesn't seem to be a way to shift away from
reduce without breaking existing pickles.  

It's unfortunate that pickling provides so many different hooks and they
don't all play nice with one another.
History
Date User Action Args
2022-04-11 14:56:13adminsetgithub: 42483
2009-03-21 00:44:42rhettingersetstatus: open -> closed
resolution: wont fix
messages: + msg83904
2009-03-20 23:38:46rhettingersetassignee: tim.peters -> rhettinger
2009-03-20 22:59:11ajaksu2setversions: + Python 2.6, - Python 2.4
nosy: + ajaksu2

messages: + msg83881

components: + Library (Lib), - None
type: behavior
2005-10-14 06:38:45gsakkiscreate