summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-08-15 11:29:27 (GMT)
committerGitHub <noreply@github.com>2022-08-15 11:29:27 (GMT)
commit3ef3c6306def489ba9115f0a8a57ab1e99795a5c (patch)
treef74aa199f7051f57b4577f9a920cf982766a65b4 /Lib
parent4a7f5a55dc88c14cef880ae38a96018514ca9d83 (diff)
downloadcpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.zip
cpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.tar.gz
cpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.tar.bz2
GH-95707: Fix uses of `Py_TPFLAGS_MANAGED_DICT` (GH-95854)
* Make sure that tp_dictoffset is correct with Py_TPFLAGS_MANAGED_DICT is set. * Avoid traversing managed dict twice when subclassing class with Py_TPFLAGS_MANAGED_DICT set.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi.py24
-rw-r--r--Lib/test/test_sys.py2
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 1ff14e7..e4d2035 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -539,6 +539,30 @@ class CAPITest(unittest.TestCase):
inst = _testcapi.HeapCTypeWithDict()
self.assertEqual({}, inst.__dict__)
+ def test_heaptype_with_managed_dict(self):
+ inst = _testcapi.HeapCTypeWithManagedDict()
+ inst.foo = 42
+ self.assertEqual(inst.foo, 42)
+ self.assertEqual(inst.__dict__, {"foo": 42})
+
+ inst = _testcapi.HeapCTypeWithManagedDict()
+ self.assertEqual({}, inst.__dict__)
+
+ a = _testcapi.HeapCTypeWithManagedDict()
+ b = _testcapi.HeapCTypeWithManagedDict()
+ a.b = b
+ b.a = a
+ del a, b
+
+ def test_sublclassing_managed_dict(self):
+
+ class C(_testcapi.HeapCTypeWithManagedDict):
+ pass
+
+ i = C()
+ i.spam = i
+ del i
+
def test_heaptype_with_negative_dict(self):
inst = _testcapi.HeapCTypeWithNegativeDict()
inst.foo = 42
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 05fbcc1..78da09d 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1287,7 +1287,7 @@ class SizeofTest(unittest.TestCase):
def __sizeof__(self):
return int(self)
self.assertEqual(sys.getsizeof(OverflowSizeof(sys.maxsize)),
- sys.maxsize + self.gc_headsize)
+ sys.maxsize + self.gc_headsize*2)
with self.assertRaises(OverflowError):
sys.getsizeof(OverflowSizeof(sys.maxsize + 1))
with self.assertRaises(ValueError):