mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py (gh-136538)
This commit is contained in:
parent
92c0c45563
commit
aa4b5a77f3
1 changed files with 29 additions and 4 deletions
|
|
@ -859,7 +859,12 @@ def __init__(self, arg):
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -874,11 +879,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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue