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
PyObject_SetAttr doesn't mention value = NULL #66238
PyObject_SetAttr, when called with value == NULL, actually deletes the attribute, but the documentation doesn't say it. It mentions PyObject_DelAttr, but it is only a macro and can therefore not be looked up using e.g. ctypes.
See two alternative issues: bpo-25701 for documenting existing behavior, and bpo-25773 for deprecating it (and converting PyObject_DelAttr to a function).
This cannot be changed in 3.x, since the PyObject_DelAttr macro calls PyObject_SetAttr(..., NULL), and the macro is expanded in all extensions that use the stable ABI.
(Technically, it would be possible to add a PyObject_SetAttr *macro* that would warn/fail, while keeping the PyObject_SetAttr *function* untouched, but that would be a pain to test/maintain.)
The wording could be clarified to something like: "This behaviour is deprecated in favour of using PyObject_DelAttr(), but there are currently no plans to remove it."
New changeset 3bf6315 by Irit Katriel in branch 'main': bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639) 3bf6315
New changeset 7b694b8 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639) (GH-30685) 7b694b8
New changeset 0861a50 by Miss Islington (bot) in branch '3.10': bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639) (GH-30684) 0861a50
Activity
pitrou commentedon Jul 22, 2014
PyObject_SetAttr, when called with value == NULL, actually deletes the attribute, but the documentation doesn't say it. It mentions PyObject_DelAttr, but it is only a macro and can therefore not be looked up using e.g. ctypes.
serhiy-storchaka commentedon Dec 2, 2015
See two alternative issues: bpo-25701 for documenting existing behavior, and bpo-25773 for deprecating it (and converting PyObject_DelAttr to a function).
vadmium commentedon Nov 30, 2016
As of bpo-25701, the null-to-delete feature is documented as being deprecated in favour of calling the related Del functions or macros. There was a python-dev thread at <https://marc.info/?i=n32kch$eie$1@ger.gmane.org\>.
I’m not sure if that is good enough, or do we need to e.g. clarify that the deprecation is only at the API (C header) level, and not the ABI level?
iritkatriel commentedon Aug 2, 2021
This behaviour is documented as deprecated all the way back to 2.7. Should we repurpose the issue to removing it? Otherwise it can be closed.
https://docs.python.org/2.7/c-api/object.html#c.PyObject_SetAttr
iritkatriel commentedon Jan 17, 2022
I read the python-dev thread now and I see it was decided that it’s not worth removing it.
In recent versions of the doc it is mentioned that the function is in the stable ABI. Should we clarify exactly what is meant by ‘deprecated’?
encukou commentedon Jan 17, 2022
This cannot be changed in 3.x, since the PyObject_DelAttr macro calls PyObject_SetAttr(..., NULL), and the macro is expanded in all extensions that use the stable ABI.
(Technically, it would be possible to add a PyObject_SetAttr *macro* that would warn/fail, while keeping the PyObject_SetAttr *function* untouched, but that would be a pain to test/maintain.)
The wording could be clarified to something like: "This behaviour is deprecated in favour of using PyObject_DelAttr(), but there are currently no plans to remove it."
iritkatriel commentedon Jan 19, 2022
New changeset 3bf6315 by Irit Katriel in branch 'main':
bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639)
3bf6315
miss-islington commentedon Jan 19, 2022
New changeset 7b694b8 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639) (GH-30685)
7b694b8
iritkatriel commentedon Jan 19, 2022
New changeset 0861a50 by Miss Islington (bot) in branch '3.10':
bpo-22039: [doc] clarify that there are no plans to disable deleting an attribute via PyObject_SetAttr (GH-30639) (GH-30684)
0861a50