diff options
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 1980fcb..0801d9f 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3676,6 +3676,32 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, goto finally; } + /* If this is an immutable type, check if all bases are also immutable, + * and (for now) fire a deprecation warning if not. + * (This isn't necessary for static types: those can't have heap bases, + * and only heap types can be mutable.) + */ + if (spec->flags & Py_TPFLAGS_IMMUTABLETYPE) { + for (int i=0; i<PyTuple_GET_SIZE(bases); i++) { + PyTypeObject *b = (PyTypeObject*)PyTuple_GET_ITEM(bases, i); + if (!b) { + goto finally; + } + if (!_PyType_HasFeature(b, Py_TPFLAGS_IMMUTABLETYPE)) { + if (PyErr_WarnFormat( + PyExc_DeprecationWarning, + 0, + "Creating immutable type %s from mutable base %s is " + "deprecated, and slated to be disallowed in Python 3.14.", + spec->name, + b->tp_name)) + { + goto finally; + } + } + } + } + /* Calculate the metaclass */ if (!metaclass) { |