-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Use Py_T_OBJECT_EX instead of _Py_T_OBJECT #107253
Copy link
Copy link
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
_Py_T_OBJECTis considered legacy PyMemberDef type. The difference between_Py_T_OBJECTandPy_T_OBJECT_EXis that the former returnsNoneif readNULL, while the latter raises AttrributeError._Py_T_OBJECTmanifests itself in two effects:None, even if it was not initialized in the constructor. It is a desirable behavior in some cases.None. You cannot truly delete it.A
Py_T_OBJECT_EXmember behaves like a normal attribute in Python object, while a_Py_T_OBJECTmember behaves like in the case when the corresponding class attribute was set toNone:What if replace
_Py_T_OBJECTwithPy_T_OBJECT_EX? It turns out that you can replace it in 105 sites but 31 sites should keep_Py_T_OBJECTto make existing tests pass. This is not a very reliable result because the tests may not cover all cases. On the other hand, some tests are too picky and check the attributes of a newly created uninitialized object, even if they are normally initialized.In any case, we can take these results and replace
_Py_T_OBJECTwithPy_T_OBJECT_EXon case by case basis.@vstinner @encukou
Linked PRs