Why not deprecate Py_XDECREF in a future python version? Maybe a DeprecationWarning for now?

After going through the https://github.com/python/cpython/blob/master/Include/object.h it seems that Py_XDECREF is just calling Py_DECREF if the PyObject pointer is not NULL. This if statement could be directly implemented in Py_DECREF right? Therefore is it really required to have Py_XDECREF? Why not use a DeprecationWarning for now and plan to deprecate Py_XDECREF in the near future? How about implementing an if statement in Py_DECREF to make it work like Py_XDECREF? Thanking you, With Regards

On Thu, Apr 15, 2021 at 5:05 PM Shreyan Avigyan <pythonshreyan09@gmail.com> wrote:
After going through the https://github.com/python/cpython/blob/master/Include/object.h it seems that Py_XDECREF is just calling Py_DECREF if the PyObject pointer is not NULL. This if statement could be directly implemented in Py_DECREF right? Therefore is it really required to have Py_XDECREF? Why not use a DeprecationWarning for now and plan to deprecate Py_XDECREF in the near future? How about implementing an if statement in Py_DECREF to make it work like Py_XDECREF?
If you know for sure that it isn't NULL, why have an unnecessary branch? More importantly: why change things? How much is gained by the deprecation? ChrisA

15.04.21 10:03, Shreyan Avigyan пише:
After going through the https://github.com/python/cpython/blob/master/Include/object.h it seems that Py_XDECREF is just calling Py_DECREF if the PyObject pointer is not NULL. This if statement could be directly implemented in Py_DECREF right? Therefore is it really required to have Py_XDECREF? Why not use a DeprecationWarning for now and plan to deprecate Py_XDECREF in the near future? How about implementing an if statement in Py_DECREF to make it work like Py_XDECREF?
Py_XDECREF is a convenient macro which allows you to write one line Py_XDECREF(obj); instead of 3 lines if (obj != NULL) { Py_DECREF(obj); } The code would look uglier without it. Also, it is very difficult to deprecate it, because it is one of most used macros/functions. You propose to break all existing extensions. What exactly problem do you try to solve?

Thanks for clarifying. And I wasn't telling to write if (obj != NULL) { Py_DECREF(obj); } I was actually proposing to change the code in the static inline function _Py_DECREF by putting all of the code in the function inside the if block. But Chris has a point. If we know for sure that it isn't NULL, why have an unnecessary branch? And it's true. It would have to execute one more step (the if block) every time Py_DECREF is used when it is actually not needed. Moreover I thought about what you said Serhiy about breaking every bit of code. Actually I knew it would break that's why I said in future Python version. But anyway it's not necessary to change Py_DECREF and moreover deprecating Py_XDECREF would cause even more problem. Thanking you, With Regards
participants (3)
-
Chris Angelico
-
Serhiy Storchaka
-
Shreyan Avigyan