IMO, we can drop most (all?) of the huge comment before the check in object_set_class(). History is preserved in the git log. Contrary to Py_TPFLAGS_HEAPTYPE, using Py_TPFLAGS_IMMUTABLETYPE speaks for itself. We might reduce it to just refer to to bpo-43908 and bpo-24912. Something a la this: /* Historically, only static types were immutable. * Py_TPFLAGS_IMMUTABLETYPE was introduced in Python 3.10. * See bpo-43908 and bpo-24912. */ What do you think?
> IMO, we can drop most (all?) of the huge comment before the check in object_set_class(). I don't think so. I don't understand why it's allowed to override the __class__ attribute of ModuleType instances whereas it's a static type. IMO the long comment remains useful and something should be done later to make the condition more generic, rather than checking PyType_IsSubtype(newto, &PyModule_Type) specifically.
> Ok! Did you see bpo-24912 regarding the ModuleType check? No, I didn't. Sorry, there are too many things to look at, and too little bit. Do you think that something should be changed? If yes, please open a new separated issue.