diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-24 21:14:23 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-24 21:14:23 +0300 |
| commit | 8cd1dbae32d9303caac3a473d3332f17bc98c921 (patch) | |
| tree | 883e8288636eb076d168d2ea57b7a406e2a9d429 /Lib/test/pickletester.py | |
| parent | 473db47747bb8bc986d88ad81799bcbd88153ac5 (diff) | |
| download | cpython-git-8cd1dbae32d9303caac3a473d3332f17bc98c921.tar.gz | |
bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 (GH-22870)
Diffstat (limited to 'Lib/test/pickletester.py')
| -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 fb972a3ba5..ae288f5d01 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"] |
