Commit d33e91a2 authored by Tres Seaver's avatar Tres Seaver

Fix __getstate__ when derived class has slots.

parent f6202dbb
......@@ -262,6 +262,14 @@ class Persistent(object):
return dict([x for x in idict.items()
if not x[0].startswith('_p_') and
not x[0].startswith('_v_')])
slots = getattr(type(self), '__slots__', None)
if slots is not None:
slots = [x for x in slots
if not x.startswith('_p_') and
not x.startswith('_v_') and
x not in Persistent.__slots__]
if slots:
return None, dict([(x, getattr(self, x)) for x in slots])
return None
def __setstate__(self, state):
......@@ -358,6 +366,7 @@ class Persistent(object):
if self.__jar is not None and self.__oid is not None:
self.__jar._cache.mru(self.__oid)
def _estimated_size_in_24_bits(value):
if value > 1073741696:
return 16777215
......
......@@ -701,6 +701,15 @@ class _Persistent_Base(object):
inst._v_qux = 'spam'
self.assertEqual(inst.__getstate__(), {'foo': 'bar'})
def test___getstate___derived_w_slots(self):
class Derived(self._getTargetClass()):
__slots__ = ('foo', '_p_baz', '_v_qux')
inst = Derived()
inst.foo = 'bar'
inst._p_baz = 'bam'
inst._v_qux = 'spam'
self.assertEqual(inst.__getstate__(), (None, {'foo': 'bar'}))
def test___setstate___empty(self):
inst = self._makeOne()
inst.__setstate__(None) # doesn't raise, but doesn't change anything
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment