classification
Title: Use Py_TPFLAGS_IMMUTABLETYPE in __class__ assignments check
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: erlendaasland, gvanrossum, pitrou, shreyanavigyan, vstinner
Priority: normal Keywords: patch

Created on 2021-04-29 08:27 by erlendaasland, last changed 2021-04-30 10:58 by erlendaasland. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25714 merged erlendaasland, 2021-04-29 09:30
Messages (7)
msg392290 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-29 08:27
Use Py_TPFLAGS_IMMUTABLETYPE iso. Py_TPFLAGS_HEAPTYPE in object_set_class().

See also:
- bpo-43908 (particularly msg392286)
- bpo-24912
- https://github.com/python/cpython/blob/e047239eafefe8b19725efffe7756443495cf78b/Objects/typeobject.c#L4620-L4668
msg392291 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-29 08:35
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?
msg392313 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-29 14:17
> 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.
msg392404 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-30 10:07
New changeset b73b5fb9ea08156991a065c1696e8d8cf7622482 by Erlend Egeberg Aasland in branch 'master':
 bpo-43973: object_set_class() checks Py_TPFLAGS_IMMUTABLETYPE (GH-25714)
https://github.com/python/cpython/commit/b73b5fb9ea08156991a065c1696e8d8cf7622482
msg392405 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-30 10:09
Ok! Did you see bpo-24912 regarding the ModuleType check?
msg392412 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-30 10:44
> 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.
msg392415 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-30 10:58
> Do you think that something should be changed? If yes, please open a new separated issue.

No, my comment was just for information :)
History
Date User Action Args
2021-04-30 10:58:54erlendaaslandsetmessages: + msg392415
2021-04-30 10:44:41vstinnersetmessages: + msg392412
2021-04-30 10:09:43erlendaaslandsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-30 10:09:20erlendaaslandsetmessages: + msg392405
2021-04-30 10:07:09vstinnersetmessages: + msg392404
2021-04-29 14:17:50vstinnersetmessages: + msg392313
2021-04-29 12:44:00shreyanavigyansetnosy: + shreyanavigyan
2021-04-29 09:30:02erlendaaslandsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24403
2021-04-29 08:35:19erlendaaslandsetmessages: + msg392291
2021-04-29 08:27:05erlendaaslandcreate