[issue9269] Cannot pickle self-referencing sets

Alexander Belopolsky report at bugs.python.org
Fri Jul 16 02:17:00 CEST 2010

Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

I am reclassifying this as an RFE because as a bug, this is a duplicate of issue1062277.  The later contains an excellent description of the problem by Dima Dorfman:

     Our pickle implementations don't check for reduce
     cycles. This is somewhat cosmetic except that stack
     overflow protection is imperfect (for cPickle), causing
     crashes, and some kinds of cycles trigger asserts (in
     pickle).  [msg47267]

This is undeniably a bug and the solution offered in issue1062277 is quite reasonable: detect reduce cycles and bail out with an informative message.  This will not solve the problem of pickling self-referencing sets, but at least once documented can be defended as expected behavior.

What remains after issue1062277 is a feature request to allow pickling of self-referencing sets.  I would argue that this is really a pathological case.  Sets are not supposed to contain mutable items and immutable objects cannot create reference cycles among themselves.

The test case in cycle.py tricks set into accepting mutable objects by creating a class with default __hash__.  This falls into a category of "don't do it".

I am lowering the priority and adding #1062277 as a dependency.  Once #1062277 is fixed, I would not mind closing this as "won't fix".

dependencies: +Pickle breakage with reduction of recursive structures
priority: normal -> low
type: behavior -> feature request

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list