summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2022-08-04 14:13:45 (GMT)
committerGitHub <noreply@github.com>2022-08-04 14:13:45 (GMT)
commita613fedd6e18e4ab382cf81ec767e1135fc949a7 (patch)
tree55b93ee54133040ea0a267d614e901fc669910a6 /Modules
parent000c3874bfa63507293c22249881f6cfc61af311 (diff)
downloadcpython-a613fedd6e18e4ab382cf81ec767e1135fc949a7.zip
cpython-a613fedd6e18e4ab382cf81ec767e1135fc949a7.tar.gz
cpython-a613fedd6e18e4ab382cf81ec767e1135fc949a7.tar.bz2
gh-95388: Deprecate creating immutable types with mutable bases (GH-95533)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/heaptype.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c
index 12889e8..514541c 100644
--- a/Modules/_testcapi/heaptype.c
+++ b/Modules/_testcapi/heaptype.c
@@ -365,6 +365,21 @@ create_type_from_repeated_slots(PyObject *self, PyObject *variant_obj)
}
+
+static PyObject *
+make_immutable_type_with_base(PyObject *self, PyObject *base)
+{
+ assert(PyType_Check(base));
+ PyType_Spec ImmutableSubclass_spec = {
+ .name = "ImmutableSubclass",
+ .basicsize = (int)((PyTypeObject*)base)->tp_basicsize,
+ .slots = empty_type_slots,
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
+ };
+ return PyType_FromSpecWithBases(&ImmutableSubclass_spec, base);
+}
+
+
static PyMethodDef TestMethods[] = {
{"pytype_fromspec_meta", pytype_fromspec_meta, METH_O},
{"test_type_from_ephemeral_spec", test_type_from_ephemeral_spec, METH_NOARGS},
@@ -375,6 +390,7 @@ static PyMethodDef TestMethods[] = {
{"test_from_spec_invalid_metatype_inheritance",
test_from_spec_invalid_metatype_inheritance,
METH_NOARGS},
+ {"make_immutable_type_with_base", make_immutable_type_with_base, METH_O},
{NULL},
};