https://github.com/python/cpython/commit/08f6b3f422987e0f6f03960deb40ca993b19f7ba
commit: 08f6b3f422987e0f6f03960deb40ca993b19f7ba
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: corona10 <[email protected]>
date: 2025-10-24T11:45:44Z
summary:
[3.14] gh-136535: Tests: Correct `Py_TPFLAGS_MANAGED_DICT` in `test_class.py`
(gh-136538) (gh-140532)
files:
M Lib/test/test_class.py
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 4c12d43556fc2a..418dd9a4120585 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -858,7 +858,12 @@ def __init__(self, arg):
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:
pass
@@ -873,11 +878,31 @@ def __init__(self):
self.d = 4
+class VarSizedSubclass(tuple):
+ pass
+
+
class TestInlineValues(unittest.TestCase):
- def test_flags(self):
- self.assertEqual(Plain.__flags__ & Py_TPFLAGS_MANAGED_DICT,
Py_TPFLAGS_MANAGED_DICT)
- self.assertEqual(WithAttrs.__flags__ & Py_TPFLAGS_MANAGED_DICT,
Py_TPFLAGS_MANAGED_DICT)
+ def test_no_flags_for_slots_class(self):
+ flags = NoManagedDict.__flags__
+ 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):
c = Plain()
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]