From a7a8dc95504ca35cb541c0de26396ed105dd3bf5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Aug 2026 14:45:45 +0200 Subject: [PATCH] gh-155503: Check Py_TPFLAGS_IMMUTABLETYPE in check_immutable_type() Check for Py_TPFLAGS_IMMUTABLETYPE type flag in test.support.check_immutable_type(). --- Lib/test/support/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index f98da49171dc3b..3f2caebd21e336 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -3484,3 +3484,11 @@ def check_immutable_type(testcase, type): regex = r'cannot set .* attribute of immutable type' with testcase.assertRaisesRegex(TypeError, regex): setattr(type, 'custom_attr', 123) + + try: + from _testlimitedcapi import type_getflags, Py_TPFLAGS_IMMUTABLETYPE + except ImportError: + pass + else: + flags = type_getflags(type) + testcase.assertTrue(flags & Py_TPFLAGS_IMMUTABLETYPE)