diff options
author | Mark Shannon <mark@hotpy.org> | 2022-08-16 13:57:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 13:57:18 +0100 |
commit | 5a8c15819c27c516e5b75b7c9d89eacdb16b77c3 (patch) | |
tree | b75d585f24f97aac724952a75175cc9f15af48af /Lib/test | |
parent | 829aab859266253320317caabdb0e17fa4e0f05e (diff) | |
download | cpython-git-5a8c15819c27c516e5b75b7c9d89eacdb16b77c3.tar.gz |
GH-95245: Move weakreflist into the pre-header. (GH-95996)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_capi.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index e4d20355d4..e6516b33ae 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -579,6 +579,37 @@ class CAPITest(unittest.TestCase): self.assertEqual(ref(), inst) self.assertEqual(inst.weakreflist, ref) + def test_heaptype_with_managed_weakref(self): + inst = _testcapi.HeapCTypeWithManagedWeakref() + ref = weakref.ref(inst) + self.assertEqual(ref(), inst) + + def test_sublclassing_managed_weakref(self): + + class C(_testcapi.HeapCTypeWithManagedWeakref): + pass + + inst = C() + ref = weakref.ref(inst) + self.assertEqual(ref(), inst) + + def test_sublclassing_managed_both(self): + + class C1(_testcapi.HeapCTypeWithManagedWeakref, _testcapi.HeapCTypeWithManagedDict): + pass + + class C2(_testcapi.HeapCTypeWithManagedDict, _testcapi.HeapCTypeWithManagedWeakref): + pass + + for cls in (C1, C2): + inst = cls() + ref = weakref.ref(inst) + self.assertEqual(ref(), inst) + inst.spam = inst + del inst + ref = weakref.ref(cls()) + self.assertIs(ref(), None) + def test_heaptype_with_buffer(self): inst = _testcapi.HeapCTypeWithBuffer() b = bytes(inst) |