summaryrefslogtreecommitdiffstats
path: root/Lib/copy_reg.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/copy_reg.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/copy_reg.py')
-rw-r--r--Lib/copy_reg.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/Lib/copy_reg.py b/Lib/copy_reg.py
index f96703e..11ae960 100644
--- a/Lib/copy_reg.py
+++ b/Lib/copy_reg.py
@@ -58,6 +58,9 @@ def _reduce(self):
try:
getstate = self.__getstate__
except AttributeError:
+ if getattr(self, "__slots__", None):
+ raise TypeError("a class that defines __slots__ without "
+ "defining __getstate__ cannot be pickled")
try:
dict = self.__dict__
except AttributeError:
@@ -83,16 +86,8 @@ def _better_reduce(obj):
args = ()
getstate = getattr(obj, "__getstate__", None)
if getstate:
- try:
- state = getstate()
- except TypeError, err:
- # XXX Catch generic exception caused by __slots__
- if str(err) != ("a class that defines __slots__ "
- "without defining __getstate__ "
- "cannot be pickled"):
- raise # Not that specific exception
- getstate = None
- if not getstate:
+ state = getstate()
+ else:
state = getattr(obj, "__dict__", None)
names = _slotnames(cls)
if names: