GeezerVison is showing github.com — Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead · Issue #106572 · python/cpython
Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead #106572DescriptionWhen PyObject_SetAttr() is called with a NULL value, it's unclear if the caller wants to remove the attribute on purpose, or if the value is NULL because of an error. Such API is error prone and should be avoided.
In 2005, this feature was already deprecated in the documentation in issue #69887 by commit 45be8d6.
I propose to now emit a DeprecationWarning and schedule the removal of this feature in Python 3.15. If too many C extensions rely on this current behavior, we can consider removing the feature later.
Linked PRs
Activityvstinner commented on Jul 9, 2023 vstinner commented on Jul 9, 2023 vstinner commented on Jul 9, 2023 vstinner commented on Jul 9, 2023 We should consider deprecating similar APIs used to delete an item/attribute:
PyObject_SetItem(obj, key, NULL): use PyObject_DelItem(obj, key) instead
PyMapping_SetItemString(obj, key, NULL): use PyMapping_DelItemString(obj, key) instead
PySequence_SetItem(obj, index, NULL): use PySequence_DelItem(obj, index) instead
PySequence_SetSlice(obj, i1, i2, NULL): use PySequence_DelSlice(obj, i1, i2) instead
serhiy-storchaka commented on Jul 10, 2023 Unfortunately, adding a warning will break binary compatibility. Code compiled with older Python version which uses PyObject_DelAttr() calls PyObject_SetAttr(), because PyObject_DelAttr() was implemented as a macro.
We should first implement PyObject_DelAttr() as a separate function, then in some distant future we decide to break binary compatibility with Python older than 3.13 and add a warning, then error, in PyObject_SetAttr(). vstinner commented on Jul 25, 2023
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|