From 8cd1dbae32d9303caac3a473d3332f17bc98c921 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 24 Oct 2020 21:14:23 +0300 Subject: bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 (GH-22870) --- Lib/copyreg.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Lib/copyreg.py') diff --git a/Lib/copyreg.py b/Lib/copyreg.py index dfc463c49a..7ab8c128eb 100644 --- a/Lib/copyreg.py +++ b/Lib/copyreg.py @@ -48,6 +48,7 @@ def _reconstructor(cls, base, state): return obj _HEAPTYPE = 1<<9 +_new_type = type(int.__new__) # Python code for object.__reduce_ex__ for protocols 0 and 1 @@ -57,6 +58,9 @@ def _reduce_ex(self, proto): for base in cls.__mro__: if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE: break + new = base.__new__ + if isinstance(new, _new_type) and new.__self__ is base: + break else: base = object # not really reachable if base is object: -- cgit v1.2.1