classification
Title: problem with pickling newstyle class instances
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: alexandre.vassalotti Nosy List: ajaksu2, alexandre.vassalotti, georg.brandl, tovrstra (4)
Priority: normal Keywords

Created on 2004-02-08 15:55 by tovrstra, last changed 2009-02-14 11:31 by ajaksu2.

Files
File name Uploaded Description Edit Remove
pickletest.py tovrstra, 2004-02-08 15:55 pickletest.py
Messages (4)
msg19940 - (view) Author: Toon Verstraelen (tovrstra) Date: 2004-02-08 15:55
My python version:

Python 2.3.3 (#1, Jan 25 2004, 21:45:01)
[GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3,
propolice)] on linux2

Please try the example. That will explain a lot. The
problem is that not all new style class instances are
picklable. In my example a class is derived from a list
and a base class. The list-descendant contains an
instance of the base class, which has a reference to
the list containing it. with cPickle things work fine,
but not for the normal pickle routines

class subitem:
	def __init__(self, parent):
		self.parent = parent
		if parent != None:
			parent.append(self)

class group(subitem, list):
	def __init__(self, parent):
		subitem.__init__(self, parent)
		

g = group(None)
s = subitem(g)

import cPickle
print cPickle.dumps(g)

import pickle
print pickle.dumps(g)
msg19941 - (view) Author: Georg Brandl (georg.brandl) Date: 2005-10-01 13:40
Logged In: YES 
user_id=1188172

Verified in 2.5cvs.
msg58057 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) Date: 2007-12-01 17:35
Please assign this bug to me.

Note that neither cPickle or pickle is able to load the stream generated
by cPickle correctly:

   >>> g = group(None)
   >>> subitem(g)
   >>> g[0].parent is g
   True
   >>> gp = cPickle.loads(cPickle.dumps(g))
   >>> gp[0].parent is gp
   False

I don't think that will be easy to fix, but I will try to see what I can do.
msg82010 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-02-14 11:31
Confirmed on trunk.
History
Date User Action Args
2009-02-14 11:31:46ajaksu2setnosy: + ajaksu2
stage: test needed
messages: + msg82010
versions: + Python 2.6, - Python 2.3
2007-12-01 18:00:25alexandre.vassalottisetassignee: alexandre.vassalotti
2007-12-01 17:35:21alexandre.vassalottisetnosy: + alexandre.vassalotti
type: behavior
messages: + msg58057
components: + Library (Lib), - Interpreter Core
2004-02-08 15:55:57tovrstracreate