A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/issues/105944 below:

Remove PyObject_Init() return value · Issue #105944 · python/cpython · GitHub

PyObject_Init(), PyObject_INIT(), PyObject_InitVar() and PyObject_INIT_VAR() return their argument which is technically a borrowed reference. For me, this API is really surprising. Why would someone like to rely on the return value, since the result is already known: it's the input argument?

I propose to remove the return value of these 4 PyObject "INIT" functions.

On PyPI top 5,000 projects (2023-04-13), I found 3 projects using these functions, but none are affected by proposed change:

I searched for PyObject_INIT regex.

Cython is not affected, since it already ignores the result explicitly:

code.putln("(void) PyObject_INIT(o, t);")

There is also boost-python (used by scipy 1.10.1) which defines PyObject_INIT() if it's not defined... for Python 1.x :-) Python 3 is not affected.

#if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2
# define PyObject_INIT(op, typeobj) \
        ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#endif

pyjson5 (1.6.2) declares PyObject_INIT() and PyObject_InitVar() functions in a Cython binding... without using them. So it's not affected neither.

cdef extern from 'Python.h':
    # ...
    object ObjectInit 'PyObject_INIT'(PyObject *obj, type cls)
    PyVarObject *ObjectInitVar 'PyObject_InitVar'(PyVarObject *obj, type cls, Py_ssize_t size)
    object PyLong_FromString(const char *str, char **pend, int base)
    # ...

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4