summaryrefslogtreecommitdiffstats
path: root/Lib/copyreg.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-10-31 00:28:07 (GMT)
committerGitHub <noreply@github.com>2018-10-31 00:28:07 (GMT)
commit0353b4eaaf451ad463ce7eb3074f6b62d332f401 (patch)
treeee6c8d6f8368ae88711440e187aaa7294f423f6c /Lib/copyreg.py
parent3f819ca138db6945ee4271bf13e42db9f9b3b1e4 (diff)
downloadcpython-0353b4eaaf451ad463ce7eb3074f6b62d332f401.zip
cpython-0353b4eaaf451ad463ce7eb3074f6b62d332f401.tar.gz
cpython-0353b4eaaf451ad463ce7eb3074f6b62d332f401.tar.bz2
bpo-33138: Change standard error message for non-pickleable and non-copyable types. (GH-6239)
Diffstat (limited to 'Lib/copyreg.py')
-rw-r--r--Lib/copyreg.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/copyreg.py b/Lib/copyreg.py
index bbe1af4..dfc463c 100644
--- a/Lib/copyreg.py
+++ b/Lib/copyreg.py
@@ -53,7 +53,8 @@ _HEAPTYPE = 1<<9
def _reduce_ex(self, proto):
assert proto < 2
- for base in self.__class__.__mro__:
+ cls = self.__class__
+ for base in cls.__mro__:
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
break
else:
@@ -61,16 +62,18 @@ def _reduce_ex(self, proto):
if base is object:
state = None
else:
- if base is self.__class__:
- raise TypeError("can't pickle %s objects" % base.__name__)
+ if base is cls:
+ raise TypeError(f"cannot pickle {cls.__name__!r} object")
state = base(self)
- args = (self.__class__, base, state)
+ args = (cls, base, state)
try:
getstate = self.__getstate__
except AttributeError:
if getattr(self, "__slots__", None):
- raise TypeError("a class that defines __slots__ without "
- "defining __getstate__ cannot be pickled") from None
+ raise TypeError(f"cannot pickle {cls.__name__!r} object: "
+ f"a class that defines __slots__ without "
+ f"defining __getstate__ cannot be pickled "
+ f"with protocol {proto}") from None
try:
dict = self.__dict__
except AttributeError: