[Patches] [ python-Patches-1062353 ] set pickling problems

SourceForge.net noreply at sourceforge.net
Mon Nov 8 12:07:49 CET 2004


Patches item #1062353, was opened at 2004-11-08 11:07
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1062353&group_id=5470

Category: Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dima Dorfman (ddorfman)
Assigned to: Nobody/Anonymous (nobody)
Summary: set pickling problems

Initial Comment:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1062353&group_id=5470


More information about the Patches mailing list