You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use Py_TPFLAGS_IMMUTABLETYPE in __class__ assignments check #88139
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.
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.
Activity
erlend-aasland commentedon Apr 29, 2021
Use Py_TPFLAGS_IMMUTABLETYPE iso. Py_TPFLAGS_HEAPTYPE in object_set_class().
See also:
cpython/Objects/typeobject.c
Lines 4620 to 4668 in e047239
erlend-aasland commentedon Apr 29, 2021
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.
What do you think?
vstinner commentedon Apr 29, 2021
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.
vstinner commentedon Apr 30, 2021
New changeset b73b5fb by Erlend Egeberg Aasland in branch 'master':
bpo-43973: object_set_class() checks Py_TPFLAGS_IMMUTABLETYPE (GH-25714)
b73b5fb
erlend-aasland commentedon Apr 30, 2021
Ok! Did you see bpo-24912 regarding the ModuleType check?
vstinner commentedon Apr 30, 2021
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.
erlend-aasland commentedon Apr 30, 2021
No, my comment was just for information :)