[New-bugs-announce] [issue13479] pickle to picky on re-defined classes

kxroberto report at bugs.python.org
Fri Nov 25 10:02:43 CET 2011

New submission from kxroberto <kxroberto at users.sourceforge.net>:

When a class definition was re-executed (reload, exec ..) , pickling of existing instances fails for to picky reason (class object id mismatch). Solved by the one liner patch below.

Rational: Python is dynamic. Like with any normal attribute lookup: When its the same module/..name  this class is really meant - no matter about its id. 
(During unpickling its another id anyway, the code may have evolved years ...)

diff -ur --strip _orig/pickle.py ./pickle.py
--- _orig/pickle.py	2008-09-08 10:58:32 +0000
+++ ./pickle.py	2011-11-24 15:47:11 +0000
@@ -747,7 +747,7 @@
                 "Can't pickle %r: it's not found as %s.%s" %
                 (obj, module, name))
-            if klass is not obj:
+            if klass.__name__ != obj.__name__:
                 raise PicklingError(
                     "Can't pickle %r: it's not the same object as %s.%s" %
                     (obj, module, name))

components: Library (Lib)
messages: 148311
nosy: kxroberto
priority: normal
severity: normal
status: open
title: pickle to picky on re-defined classes
type: crash
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list