gh-114329: Add PyList_GetItemRef function#114504
Conversation
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
When I proposed such change, @serhiy-storchaka asked me to stick to |
Sorry, something went wrong.
Is it RuntimeError or SystemError? The only discussed difference was returning a strong reference instead of a weak reference. If we want to change also the exception type, it should be a separate discussion. Most concrete type C API raises SystemError if they are called with wrong type. It is considered a programming error, not a data error. |
Sorry, something went wrong.
I suggest to document that the function "parameter must be list" , without mentioning the exact exception type. |
Sorry, something went wrong.
The |
Sorry, something went wrong.
|
I've removed the sentence mentioning |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
The TypeError behavior is explicitly stated in the C API WG capi-workgroup/decisions#9 (comment). See also capi-workgroup/api-evolution#29 (comment) and PyWeakref_GetRef().
Oh ok, I didn't notice that TypeError was explicitly mentioned.
Sorry, something went wrong.
corona10
left a comment
There was a problem hiding this comment.
LGTM too.
I will merge the PR if @serhiy-storchaka approve.
Sorry, something went wrong.
encukou
left a comment
There was a problem hiding this comment.
If the WG does discuss the exception type, it'll take some time.
Let's merge this, the type can be changed later
Sorry, something went wrong.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
The new
PyList_GetItemRefis similar toPyList_GetItem, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets aTypeErrorinstead of callingPyErr_BadInternalCall().PyList_GetItemRef, a variant ofPyList_GetItemthat returns a strong reference #114329📚 Documentation preview 📚: https://cpython-previews--114504.org.readthedocs.build/