Skip to content

Commit 8b38c42

Browse files
ever0demiss-islington
authored andcommitted
pythongh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py (pythongh-136538)
(cherry picked from commit aa4b5a7) Co-authored-by: Jiseok CHOI <[email protected]>
1 parent 6efd78d commit 8b38c42

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

Lib/test/test_class.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,12 @@ def __init__(self, arg):
858858

859859
from _testinternalcapi import has_inline_values
860860

861-
Py_TPFLAGS_MANAGED_DICT = (1 << 2)
861+
Py_TPFLAGS_INLINE_VALUES = (1 << 2)
862+
Py_TPFLAGS_MANAGED_DICT = (1 << 4)
863+
864+
class NoManagedDict:
865+
__slots__ = ('a',)
866+
862867

863868
class Plain:
864869
pass
@@ -873,11 +878,31 @@ def __init__(self):
873878
self.d = 4
874879

875880

881+
class VarSizedSubclass(tuple):
882+
pass
883+
884+
876885
class TestInlineValues(unittest.TestCase):
877886

878-
def test_flags(self):
879-
self.assertEqual(Plain.__flags__ & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
880-
self.assertEqual(WithAttrs.__flags__ & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
887+
def test_no_flags_for_slots_class(self):
888+
flags = NoManagedDict.__flags__
889+
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, 0)
890+
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, 0)
891+
self.assertFalse(has_inline_values(NoManagedDict()))
892+
893+
def test_both_flags_for_regular_class(self):
894+
for cls in (Plain, WithAttrs):
895+
with self.subTest(cls=cls.__name__):
896+
flags = cls.__flags__
897+
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
898+
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, Py_TPFLAGS_INLINE_VALUES)
899+
self.assertTrue(has_inline_values(cls()))
900+
901+
def test_managed_dict_only_for_varsized_subclass(self):
902+
flags = VarSizedSubclass.__flags__
903+
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
904+
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, 0)
905+
self.assertFalse(has_inline_values(VarSizedSubclass()))
881906

882907
def test_has_inline_values(self):
883908
c = Plain()

0 commit comments

Comments
 (0)