mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
gh-95388: Deprecate creating immutable types with mutable bases (GH-95533)
This commit is contained in:
parent
000c3874bf
commit
a613fedd6e
5 changed files with 80 additions and 0 deletions
|
@ -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},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue