]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43973: object_set_class() checks Py_TPFLAGS_IMMUTABLETYPE (GH-25714)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Fri, 30 Apr 2021 10:07:02 +0000 (12:07 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Apr 2021 10:07:02 +0000 (12:07 +0200)
Use Py_TPFLAGS_IMMUTABLETYPE to check for class assignments.

Objects/typeobject.c

index 19d619fada0e984aa3f6be2d3b29b2d44233309d..1f8e2572a2daf9dcd83bdb94eb39cd0bd2fb0ec7 100644 (file)
@@ -4737,10 +4737,10 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
     */
     if (!(PyType_IsSubtype(newto, &PyModule_Type) &&
           PyType_IsSubtype(oldto, &PyModule_Type)) &&
-        (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
-         !(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE))) {
+        (_PyType_HasFeature(newto, Py_TPFLAGS_IMMUTABLETYPE) ||
+         _PyType_HasFeature(oldto, Py_TPFLAGS_IMMUTABLETYPE))) {
         PyErr_Format(PyExc_TypeError,
-                     "__class__ assignment only supported for heap types "
+                     "__class__ assignment only supported for mutable types "
                      "or ModuleType subclasses");
         return -1;
     }