GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-114329: Add `PyList_GetItemRef` function by colesbury · Pull Request #114504 · python/cpython Conversation
|
When I proposed such change, @serhiy-storchaka asked me to stick to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| :exc:`TypeError` exception. | ||
|
|
||
| This behaves like :c:func:`PyList_GetItem`, but returns a | ||
| :term:`strong reference` instead of a :term:`borrowed reference`. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest to make this function the new reference, and document PyList_GetItem() as: "Similar to PyList_GetItemRef(), but return a borrowed reference".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # CRASHES get_item(21, 2) | ||
| # CRASHES get_item(NULL, 1) | ||
|
|
||
| def test_list_get_item_ref(self): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you share most code between test_list_get_item() and test_list_get_item_ref()?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| [function.PyList_GetItemRef] | ||
| added = '3.13' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Move it to the end of the file.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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.
There was an error while loading. Please reload this page.
I suggest to document that the function "parameter must be list" , without mentioning the exact exception type. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've removed the sentence mentioning |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM too.
I will merge the PR if @serhiy-storchaka approve.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Erlend E. Aasland <[email protected]>
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()`.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.