diff options
author | Petr Viktorin <encukou@gmail.com> | 2023-05-03 13:17:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 13:17:14 (GMT) |
commit | 524a7f77fd8244835e382f076dd4a76404580bb3 (patch) | |
tree | 2c4cf20e01075972e4861d8cfc54ec5902af1233 /Modules/_testcapi | |
parent | 423d7faeb37b6c13b3ebbf9255165fefc651983e (diff) | |
download | cpython-524a7f77fd8244835e382f076dd4a76404580bb3.zip cpython-524a7f77fd8244835e382f076dd4a76404580bb3.tar.gz cpython-524a7f77fd8244835e382f076dd4a76404580bb3.tar.bz2 |
gh-103968: Deprecate creating heap types whose metaclass has custom tp_new. (GH-103972)
(That's a mouthful of an edge case!)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r-- | Modules/_testcapi/heaptype.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c index 209cc18..6384fbc 100644 --- a/Modules/_testcapi/heaptype.c +++ b/Modules/_testcapi/heaptype.c @@ -22,7 +22,7 @@ static PyObject *pytype_fromspec_meta(PyObject* self, PyObject *meta) "_testcapi.HeapCTypeViaMetaclass", sizeof(PyObject), 0, - Py_TPFLAGS_DEFAULT, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, HeapCTypeViaMetaclass_slots }; @@ -385,6 +385,19 @@ make_immutable_type_with_base(PyObject *self, PyObject *base) return PyType_FromSpecWithBases(&ImmutableSubclass_spec, base); } +static PyObject * +make_type_with_base(PyObject *self, PyObject *base) +{ + assert(PyType_Check(base)); + PyType_Spec ImmutableSubclass_spec = { + .name = "_testcapi.Subclass", + .basicsize = (int)((PyTypeObject*)base)->tp_basicsize, + .slots = empty_type_slots, + .flags = Py_TPFLAGS_DEFAULT, + }; + return PyType_FromSpecWithBases(&ImmutableSubclass_spec, base); +} + static PyMethodDef TestMethods[] = { {"pytype_fromspec_meta", pytype_fromspec_meta, METH_O}, @@ -397,6 +410,7 @@ static PyMethodDef TestMethods[] = { test_from_spec_invalid_metatype_inheritance, METH_NOARGS}, {"make_immutable_type_with_base", make_immutable_type_with_base, METH_O}, + {"make_type_with_base", make_type_with_base, METH_O}, {NULL}, }; |