[Python-checkins] python/dist/src/Lib/test test_descr.py,1.179,1.180
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Mon, 10 Feb 2003 13:31:29 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv25780/Lib/test
Modified Files:
test_descr.py
Log Message:
Get rid of the "bozo" __getstate__ that was inserted when __slots__
was used. This simplifies some logic in copy_reg.py (used by
pickling). It also broke a test, but this was rewritten to test the
new feature. :-)
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.179
retrieving revision 1.180
diff -C2 -d -r1.179 -r1.180
*** test_descr.py 10 Feb 2003 02:12:43 -0000 1.179
--- test_descr.py 10 Feb 2003 21:31:26 -0000 1.180
***************
*** 2836,2840 ****
else:
raise TestFailed, "should fail: cPickle D instance - %s" % base
! # Give C a __getstate__ and __setstate__
class C(base):
__slots__ = ['a']
--- 2836,2840 ----
else:
raise TestFailed, "should fail: cPickle D instance - %s" % base
! # Give C a nice generic __getstate__ and __setstate__
class C(base):
__slots__ = ['a']
***************
*** 2844,2851 ****
except AttributeError:
d = {}
! try:
! d['a'] = self.a
! except AttributeError:
! pass
return d
def __setstate__(self, d):
--- 2844,2853 ----
except AttributeError:
d = {}
! for cls in self.__class__.__mro__:
! for sn in cls.__dict__.get('__slots__', ()):
! try:
! d[sn] = getattr(self, sn)
! except AttributeError:
! pass
return d
def __setstate__(self, d):
***************
*** 2872,2890 ****
y = cPickle.loads(cPickle.dumps(x))
vereq(y.a + y.b, 142)
! # But a subclass that adds a slot should not work
class E(C):
__slots__ = ['b']
! try:
! pickle.dumps(E())
! except TypeError:
! pass
! else:
! raise TestFailed, "should fail: pickle E instance - %s" % base
! try:
! cPickle.dumps(E())
! except TypeError:
! pass
! else:
! raise TestFailed, "should fail: cPickle E instance - %s" % base
def copies():
--- 2874,2889 ----
y = cPickle.loads(cPickle.dumps(x))
vereq(y.a + y.b, 142)
! # A subclass that adds a slot should also work
class E(C):
__slots__ = ['b']
! x = E()
! x.a = 42
! x.b = "foo"
! y = pickle.loads(pickle.dumps(x))
! vereq(y.a, x.a)
! vereq(y.b, x.b)
! y = cPickle.loads(cPickle.dumps(x))
! vereq(y.a, x.a)
! vereq(y.b, x.b)
def copies():