mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
[3.9] bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 (GH-22870). (GH-22963)
(cherry picked from commit 8cd1dbae32)
This commit is contained in:
parent
af891a962b
commit
0aaecb3048
5 changed files with 25 additions and 35 deletions
|
|
@ -1965,6 +1965,17 @@ def test_newobj_proxies(self):
|
|||
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
|
||||
|
|
@ -3085,6 +3096,13 @@ class MyFrozenSet(frozenset):
|
|||
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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue