-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead #106572
Comments
python-dev discussion in 2015: https://mail.python.org/archives/list/python-dev@python.org/thread/OSKS23WDHU67NQCANPNSAPHATZ2J3W7T/ |
I wrote PR #105373 to remove the deprecation in the documentation, but @serhiy-storchaka wrote that the deprecation should stay: #105374 (comment) Copy of his message: The Gmane link no longer work, the working links to the discussion (it was split on several threads) are The problems with the current behavior:
Changing the current behavior is a long process. M.-A. Lemburg specified the required procedure. It is interesting, that if we started it in 3.6, it would already be finished. |
I reported this error prone API as capi-workgroup/problems#47 |
We should consider deprecating similar APIs used to delete an item/attribute:
|
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name). * weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name). * weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name). * weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
Unfortunately, adding a warning will break binary compatibility. Code compiled with older Python version which uses We should first implement |
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name). * weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
If the alue is NULL, PyObject_SetAttr() and PyObject_SetAttrString() emit a DeprecationWarning in Python Development Mode or if Python is built in debug mode. weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
If the value is NULL, PyObject_SetAttr() and PyObject_SetAttrString() emit a DeprecationWarning in Python Development Mode or if Python is built in debug mode. weakref proxy_setattr() calls PyObject_DelAttr() if value is NULL.
I close the issue: see #106573 (comment) |
When
PyObject_SetAttr()
is called with aNULL
value, it's unclear if the caller wants to remove the attribute on purpose, or if the value isNULL
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
The text was updated successfully, but these errors were encountered: