diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-24 18:14:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-24 18:14:23 (GMT) |
commit | 8cd1dbae32d9303caac3a473d3332f17bc98c921 (patch) | |
tree | 883e8288636eb076d168d2ea57b7a406e2a9d429 /Lib/test | |
parent | 473db47747bb8bc986d88ad81799bcbd88153ac5 (diff) | |
download | cpython-8cd1dbae32d9303caac3a473d3332f17bc98c921.zip cpython-8cd1dbae32d9303caac3a473d3332f17bc98c921.tar.gz cpython-8cd1dbae32d9303caac3a473d3332f17bc98c921.tar.bz2 |
bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 (GH-22870)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index fb972a3..ae288f5 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1969,6 +1969,17 @@ class AbstractPickleTests(unittest.TestCase): self.assertEqual(B(x), B(y), detail) self.assertEqual(x.__dict__, y.__dict__, detail) + def test_newobj_overridden_new(self): + # Test that Python class with C implemented __new__ is pickleable + for proto in protocols: + x = MyIntWithNew2(1) + x.foo = 42 + s = self.dumps(x, proto) + y = self.loads(s) + self.assertIs(type(y), MyIntWithNew2) + self.assertEqual(int(y), 1) + self.assertEqual(y.foo, 42) + def test_newobj_not_class(self): # Issue 24552 global SimpleNewObj @@ -3089,6 +3100,13 @@ myclasses = [MyInt, MyFloat, MyStr, MyUnicode, MyTuple, MyList, MyDict, MySet, MyFrozenSet] +class MyIntWithNew(int): + def __new__(cls, value): + raise AssertionError + +class MyIntWithNew2(MyIntWithNew): + __new__ = int.__new__ + class SlotList(MyList): __slots__ = ["foo"] |