Skip to content

gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py #136538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions Lib/test/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,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',)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__slots__ = ('a',)
__slots__ = ('a',)

pep 8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



class Plain:
pass
Expand All @@ -874,11 +879,31 @@ def __init__(self):
self.d = 4


class VarSizedSubclass(tuple):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class VarSizedSubclass(tuple):
class VarSizedSubclass(tuple):

pass


class TestInlineValues(unittest.TestCase):

def test_flags(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revive test_flags also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ever0de Oh it was my miss, you don't have to revive :(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, Should I drop this commit then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please revert b39ca1a

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()
Expand Down
Loading