diff options
Diffstat (limited to 'Lib/copyreg.py')
-rw-r--r-- | Lib/copyreg.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/copyreg.py b/Lib/copyreg.py index bbe1af4e2e7..dfc463c49a3 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: |