@@ -3950,9 +3950,10 @@ check_basicsize_includes_size_and_offsets(PyTypeObject* type)
3950
3950
return 1 ;
3951
3951
}
3952
3952
3953
- PyObject *
3954
- PyType_FromMetaclass (PyTypeObject * metaclass , PyObject * module ,
3955
- PyType_Spec * spec , PyObject * bases_in )
3953
+ static PyObject *
3954
+ _PyType_FromMetaclass_impl (
3955
+ PyTypeObject * metaclass , PyObject * module ,
3956
+ PyType_Spec * spec , PyObject * bases_in , int _allow_tp_new )
3956
3957
{
3957
3958
/* Invariant: A non-NULL value in one of these means this function holds
3958
3959
* a strong reference or owns allocated memory.
@@ -4127,9 +4128,21 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
4127
4128
goto finally ;
4128
4129
}
4129
4130
if (metaclass -> tp_new != PyType_Type .tp_new ) {
4130
- PyErr_SetString (PyExc_TypeError ,
4131
- "Metaclasses with custom tp_new are not supported." );
4132
- goto finally ;
4131
+ if (_allow_tp_new ) {
4132
+ if (PyErr_WarnFormat (
4133
+ PyExc_DeprecationWarning , 1 ,
4134
+ "Using PyType_Spec with metaclasses that have custom "
4135
+ "tp_new is deprecated and will no longer be allowed in "
4136
+ "Python 3.14." ) < 0 ) {
4137
+ goto finally ;
4138
+ }
4139
+ }
4140
+ else {
4141
+ PyErr_SetString (
4142
+ PyExc_TypeError ,
4143
+ "Metaclasses with custom tp_new are not supported." );
4144
+ goto finally ;
4145
+ }
4133
4146
}
4134
4147
4135
4148
/* Calculate best base, and check that all bases are type objects */
@@ -4316,22 +4329,29 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
4316
4329
return (PyObject * )res ;
4317
4330
}
4318
4331
4332
+ PyObject *
4333
+ PyType_FromMetaclass (PyTypeObject * metaclass , PyObject * module ,
4334
+ PyType_Spec * spec , PyObject * bases_in )
4335
+ {
4336
+ return _PyType_FromMetaclass_impl (metaclass , module , spec , bases_in , 0 );
4337
+ }
4338
+
4319
4339
PyObject *
4320
4340
PyType_FromModuleAndSpec (PyObject * module , PyType_Spec * spec , PyObject * bases )
4321
4341
{
4322
- return PyType_FromMetaclass (NULL , module , spec , bases );
4342
+ return _PyType_FromMetaclass_impl (NULL , module , spec , bases , 1 );
4323
4343
}
4324
4344
4325
4345
PyObject *
4326
4346
PyType_FromSpecWithBases (PyType_Spec * spec , PyObject * bases )
4327
4347
{
4328
- return PyType_FromMetaclass (NULL , NULL , spec , bases );
4348
+ return _PyType_FromMetaclass_impl (NULL , NULL , spec , bases , 1 );
4329
4349
}
4330
4350
4331
4351
PyObject *
4332
4352
PyType_FromSpec (PyType_Spec * spec )
4333
4353
{
4334
- return PyType_FromMetaclass (NULL , NULL , spec , NULL );
4354
+ return _PyType_FromMetaclass_impl (NULL , NULL , spec , NULL , 1 );
4335
4355
}
4336
4356
4337
4357
PyObject *
0 commit comments