summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-10 21:31:27 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-10 21:31:27 (GMT)
commit3f50cdc05e5254e1ce012ceca449387d50d28bc5 (patch)
treea877f2c5fec02c9b2e1db4261f0e6c64c3d53e0d /Lib/test/test_descr.py
parent0c10015a6e374544b4664eb0165aef65d986f469 (diff)
downloadcpython-3f50cdc05e5254e1ce012ceca449387d50d28bc5.zip
cpython-3f50cdc05e5254e1ce012ceca449387d50d28bc5.tar.gz
cpython-3f50cdc05e5254e1ce012ceca449387d50d28bc5.tar.bz2
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. :-)
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 8ef7979..d7368d3 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2835,7 +2835,7 @@ def pickleslots():
pass
else:
raise TestFailed, "should fail: cPickle D instance - %s" % base
- # Give C a __getstate__ and __setstate__
+ # Give C a nice generic __getstate__ and __setstate__
class C(base):
__slots__ = ['a']
def __getstate__(self):
@@ -2843,10 +2843,12 @@ def pickleslots():
d = self.__dict__.copy()
except AttributeError:
d = {}
- try:
- d['a'] = self.a
- except AttributeError:
- pass
+ 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):
for k, v in d.items():
@@ -2871,21 +2873,18 @@ def pickleslots():
vereq(y.a + y.b, 142)
y = cPickle.loads(cPickle.dumps(x))
vereq(y.a + y.b, 142)
- # But a subclass that adds a slot should not work
+ # A subclass that adds a slot should also 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
+ 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():
if verbose: print "Testing copy.copy() and copy.deepcopy()..."