diff options
author | Petr Viktorin <encukou@gmail.com> | 2024-09-13 11:18:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 11:18:49 (GMT) |
commit | 432bf31327c6b9647acb8bdb0eac2d392fd9f60a (patch) | |
tree | df69d73f4e958d5bb84b7d032ae4c37a42e87d58 /Objects | |
parent | d7e83398c188a0acd19a496ee2eeeeab52d64a11 (diff) | |
download | cpython-432bf31327c6b9647acb8bdb0eac2d392fd9f60a.zip cpython-432bf31327c6b9647acb8bdb0eac2d392fd9f60a.tar.gz cpython-432bf31327c6b9647acb8bdb0eac2d392fd9f60a.tar.bz2 |
gh-123909: PyType_From*: Disallow metaclasses with custom tp_new (GH-123947)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index a6483f7..28edd80 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4668,10 +4668,10 @@ special_offset_from_member( return -1; } -static PyObject * -_PyType_FromMetaclass_impl( +PyObject * +PyType_FromMetaclass( PyTypeObject *metaclass, PyObject *module, - PyType_Spec *spec, PyObject *bases_in, int _allow_tp_new) + PyType_Spec *spec, PyObject *bases_in) { /* Invariant: A non-NULL value in one of these means this function holds * a strong reference or owns allocated memory. @@ -4848,21 +4848,10 @@ _PyType_FromMetaclass_impl( goto finally; } if (metaclass->tp_new && metaclass->tp_new != PyType_Type.tp_new) { - if (_allow_tp_new) { - if (PyErr_WarnFormat( - PyExc_DeprecationWarning, 1, - "Type %s uses PyType_Spec with a metaclass that has custom " - "tp_new. This is deprecated and will no longer be allowed in " - "Python 3.14.", spec->name) < 0) { - goto finally; - } - } - else { - PyErr_SetString( - PyExc_TypeError, - "Metaclasses with custom tp_new are not supported."); - goto finally; - } + PyErr_SetString( + PyExc_TypeError, + "Metaclasses with custom tp_new are not supported."); + goto finally; } /* Calculate best base, and check that all bases are type objects */ @@ -5110,28 +5099,21 @@ _PyType_FromMetaclass_impl( } PyObject * -PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, - PyType_Spec *spec, PyObject *bases_in) -{ - return _PyType_FromMetaclass_impl(metaclass, module, spec, bases_in, 0); -} - -PyObject * PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { - return _PyType_FromMetaclass_impl(NULL, module, spec, bases, 1); + return PyType_FromMetaclass(NULL, module, spec, bases); } PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { - return _PyType_FromMetaclass_impl(NULL, NULL, spec, bases, 1); + return PyType_FromMetaclass(NULL, NULL, spec, bases); } PyObject * PyType_FromSpec(PyType_Spec *spec) { - return _PyType_FromMetaclass_impl(NULL, NULL, spec, NULL, 1); + return PyType_FromMetaclass(NULL, NULL, spec, NULL); } PyObject * |