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 pickling problems
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ddorfman, rhettinger
Priority: normal Keywords: patch

Created on 2004-11-08 11:07 by ddorfman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
set.diff ddorfman, 2004-11-08 11:07 Diff and tests
Messages (3)
msg47275 - (view) Author: Dima Dorfman (ddorfman) Date: 2004-11-08 11:07
As with deque (SF #1062279), two problems with set.__reduce__:

  1. Recursive sets (which can be constructed with the aid
     of a hashable mutable object) aren't pickled correctly
     because __reduce__ wants a reference to itself in the
     call to its constructor. Fix by moving the keys to the
     state argument and resurrecting them in __setstate__
     (test_pickling_recursive).

  2. Without the standard reduce, we have to take care of
     the instance dictionary ourselves. The test for this is
     in a new TestSubclassOps class that is mixed in to
     TestSetSubclass and TestFrozenSetSubclass. I'm not sure
     if such a mixin is the best way to distribute that test.

The biggest drawback to this patch is that __setstate__
makes it possible to mutate a frozenset. This implementation
clears the cached hash after such a mutation, but even then
it can be used to cause havoc in dicts. Such havoc isn't
fatal (this doesn't do anything that a regular class can't
do), but it can be confusing. Not being able to do this was
a desirable property of frozenset, but it's unlikely to
happen on accident, and sets.ImmutableSet has surived
without it. Unless one of the pickle gurus provides a better
alternative to SF #1062277, this might be the best option.
msg47276 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-11-09 07:25
Logged In: YES 
user_id=80475

Am adding the dict argument so that subclass dictionaries
are handled without extra coding.  See Objects/setobject.c 1.31

Sets were designed to be non-recursive.  While you can
create shennanigans to introduce hashable mutable objects to
be stored recursively, I have no interest in building
support for them.  Certainly, it is not worth introducing
other anomalies or worth compilcating the code.
msg47277 - (view) Author: Dima Dorfman (ddorfman) Date: 2004-11-09 09:03
Logged In: YES 
user_id=908995

Fair enough. If sets weren't meant to be recursive then 1. 31 is sufficient.
History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41152
2004-11-08 11:07:49ddorfmancreate