bpo-33138: Change standard error message for non-pickleable and non-copyable types. (GH-6239)

This commit is contained in:
Serhiy Storchaka 2018-10-31 02:28:07 +02:00 committed by GitHub
parent 3f819ca138
commit 0353b4eaaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 91 deletions

View file

@ -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: