[3.13] gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py (gh-136538) (gh-140533)

This commit is contained in:
Miss Islington (bot) 2025-10-24 13:43:32 +02:00 committed by GitHub
parent 050b9dda04
commit 166b3549d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -841,7 +841,12 @@ def __init__(self, obj):
from _testinternalcapi import has_inline_values from _testinternalcapi import has_inline_values
Py_TPFLAGS_MANAGED_DICT = (1 << 2) Py_TPFLAGS_INLINE_VALUES = (1 << 2)
Py_TPFLAGS_MANAGED_DICT = (1 << 4)
class NoManagedDict:
__slots__ = ('a',)
class Plain: class Plain:
pass pass
@ -856,11 +861,31 @@ def __init__(self):
self.d = 4 self.d = 4
class VarSizedSubclass(tuple):
pass
class TestInlineValues(unittest.TestCase): class TestInlineValues(unittest.TestCase):
def test_flags(self): def test_no_flags_for_slots_class(self):
self.assertEqual(Plain.__flags__ & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT) flags = NoManagedDict.__flags__
self.assertEqual(WithAttrs.__flags__ & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT) self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, 0)
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, 0)
self.assertFalse(has_inline_values(NoManagedDict()))
def test_both_flags_for_regular_class(self):
for cls in (Plain, WithAttrs):
with self.subTest(cls=cls.__name__):
flags = cls.__flags__
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, Py_TPFLAGS_INLINE_VALUES)
self.assertTrue(has_inline_values(cls()))
def test_managed_dict_only_for_varsized_subclass(self):
flags = VarSizedSubclass.__flags__
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, 0)
self.assertFalse(has_inline_values(VarSizedSubclass()))
def test_has_inline_values(self): def test_has_inline_values(self):
c = Plain() c = Plain()