I propose adding the following static inline function to the internal C API:
static inline PyObject* _Py_NewImmortalRef(PyObject *obj)
{
assert(_Py_IsImmortalLoose(obj));
return obj;
}
It's a way to annotate the code to express that a strong reference is expected, but we also know that the object is immortal and so calling Py_INCREF()
is not needed.
See also #103906 and #123972.
Linked PRs