summaryrefslogtreecommitdiffstats
path: root/Lib/copy_reg.py
diff options
context:
space:
mode:
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: