[Patches] [ python-Patches-1062353 ] set pickling problems
SourceForge.net
noreply at sourceforge.net
Tue Nov 9 10:03:11 CET 2004
Patches item #1062353, was opened at 2004-11-08 11:07
Message generated for change (Comment added) made by ddorfman
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1062353&group_id=5470
Category: Modules
Group: None
Status: Closed
Resolution: Wont Fix
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.
----------------------------------------------------------------------
>Comment By: Dima Dorfman (ddorfman)
Date: 2004-11-09 09:03
Message:
Logged In: YES
user_id=908995
Fair enough. If sets weren't meant to be recursive then 1. 31 is sufficient.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2004-11-09 07:25
Message:
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.
----------------------------------------------------------------------
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