gh-106572: Deprecate PyObject_SetAttr(v, name, NULL)#106573
Conversation
|
I don't think the minimum deprecation period is appropriate here. |
Sorry, something went wrong.
|
I modified the PR: it no longer plans to convert this feature to an error (in Python 3.15): it only deprecates the feature (emit DeprecationWarning). I also rebased the PR and fixed the issue number (issue #106572 is the correct issue!).
I proposed the bare minimum. If you consider that it's too short, honestly, I would prefer to just unschedule the removal and discuss it later, once we will have a better idea of how many C extensions in the wild are impacted. |
Sorry, something went wrong.
Sorry, something went wrong.
1ee5f8c to
83ac93f
Compare
July 10, 2023 12:03
encukou
left a comment
There was a problem hiding this comment.
I believe deprecating what was the way to remove attributes, just because some uses are error-prone, is too drastic and will hurt Python and its users.
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: And if you don't make the requested changes, you will be put in the comfy chair! |
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
For smoother future changes we can add a way to enable or disable this at compile time. Just surround the warning code with #ifdef SOMENAME/#endif but keep SOMENAME undefined for now. Then those who want to test it ahead can make custom Python build. What are your thoughts?
Sorry, something went wrong.
That sounds like capi-workgroup/problems#54 |
Sorry, something went wrong.
1f5bbc2 to
936bd14
Compare
July 11, 2023 21:11
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.
|
If updated my PR to only emit a DeprecationWarning in the Python Development Mode or if Python is built in debug mode.
The value can be NULL without an exception being set. What if you use PyDict_GetItem() with PyObject_SetAttr()? If the key exists in the dict, you're good. If the key doesn't exist in the dict (for whatever reason), you delete the attribute: is it what you wanted to do? There is no exception set with such weird API. Apparently, some developers don't know that this function can be used to delete attributes: see the old #69877 issue for example. |
Sorry, something went wrong.
My objection stands. |
Sorry, something went wrong.
|
Well, I propose an PR to remove the deprecation: @serhiy-storchaka disagreed. Now I propose a PR to emit a warning, @encukou disagree. @serhiy-storchaka and @encukou: can you try to agree on what should be done? My concern is that if the feature is deprecated, most people will not be aware of it without a deprecation warning emitted at runtime. Do you want to help users to discover potential bugs in their code? Or do we want to leave them alone and just write doc? |
Sorry, something went wrong.
IMO we roughly agree, at least on what should happen for 3.13? Serhiy:
me:
Are you aware of any actual users who got confused by this? ( |
Sorry, something went wrong.
@serhiy-storchaka who asked to deprecate using these functions to delete attributes: see links to previous discussions in above comments. |
Sorry, something went wrong.
We can leave the old ABI unchanged, add a new function with a different name, and leave the API unchanged: no need to expose the new name in the public API. Old ABI name, left unchanged (no warnings): SetAttr |
Sorry, something went wrong.
|
See also: capi-workgroup/problems#39 "Supporting multiple ABI versions at once". |
Sorry, something went wrong.
|
I do not disagree with @encukou. I proposed to add a runtime warning few versions after making The goal is not to break the user code, not to force them to change their code, but to help them to find potential bugs which are difficult to find now. |
Sorry, something went wrong.
DeprecationWarning is ignored by default. My proposed PR don't even emit DeprecationWarning by default, but only in Python Development Mode (-X dev). |
Sorry, something went wrong.
|
I'm +1 on Victor, emit warning only in devmode. |
Sorry, something went wrong.
|
Some developers run their tests with enabled DeprecationWarning. Could it be at least PendingDeprecationWarning? |
Sorry, something went wrong.
I don't get it. Isn't the purpose of this change helping developers to identify unsafe C API usage? If the intent is to hardly ignore the deprecation warning, maybe the whole idea of emitting a warning should be abandoned? I don't get it. |
Sorry, something went wrong.
|
We should be less persistent in forcing this change than in case of other deprecated warnings. I think it is a compromise between breaking user code and keeping the status quo. |
Sorry, something went wrong.
|
I think you're solving a non-issue -- a minor API wart we should avoid in the future, but that's it. I don't think even making the docs more complex is worth it, but, I won't block this iteration of the PR. |
Sorry, something went wrong.
|
I close the issue. I don't care enough about this issue to argue about the exact migration plan. PyObject_DelAttr() and PyObject_DelAttrString() are now implemented as a function in Python 3.13. Serhiy:
That done in commit 1f2921b. Petr:
I'm not convinced of the benefits of emitting a warning only if an exception is set. |
Sorry, something went wrong.
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.
📚 Documentation preview 📚: https://cpython-previews--106573.org.readthedocs.build/