Dear all,
I discovered a problem using cPickle.loads from CPython 2.7.6.
The last line in the following code raises an infinite recursion
class T(object):
def __init__(self):
self.item = list()
def __getattr__(self, name):
return getattr(self.item, name)
import cPickle
t = T()
l = cPickle.dumps(t)
cPickle.loads(l)
loads triggers T.__getattr__ using "getattr(inst, "__setstate__", None)" for
looking up a "__setstate__" method,
which is not implemented for T. As the item attribute is missing at this time,
the ininfite recursion starts.
The infinite recursion disappears if I attach a default implementation for
__setstate__ to T:
def __setstate__(self, dd):
self.__dict__ = dd
This could be fixed by using „hasattr“ in pickle before trying to call
„getattr“.
Is this a bug or did I miss something ?
Kind Regards,
Uwe
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com