-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-114329: Add PyList_GetItemRef
function
#114504
Changes from 3 commits
8f96d08
8c92a40
1761633
b91363f
c045495
dae4945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,15 @@ def test_list_get_item(self): | |
# CRASHES get_item(21, 2) | ||
# CRASHES get_item(NULL, 1) | ||
|
||
def test_list_get_item_ref(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()? |
||
# Test PyList_GetItemRef() | ||
get_item_ref = _testcapi.list_get_item_ref | ||
lst = [1, 2, [1, 2, 3]] | ||
self.assertEqual(get_item_ref(lst, 0), 1) | ||
self.assertEqual(get_item_ref(lst, 2), [1, 2, 3]) | ||
self.assertRaises(IndexError, get_item_ref, lst, 3) | ||
self.assertRaises(IndexError, get_item_ref, lst, -1) | ||
self.assertRaises(TypeError, get_item_ref, "not a list", 0) | ||
|
||
def test_list_setitem(self): | ||
# Test PyList_SetItem() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add :c:func:`PyList_GetItemRef`, which is similar to | ||
:c:func:`PyList_GetItem` but returns a :term:`strong reference` instead of a | ||
:term:`borrowed reference`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -905,6 +905,8 @@ | |
added = '3.2' | ||
[function.PyList_GetItem] | ||
added = '3.2' | ||
[function.PyList_GetItemRef] | ||
added = '3.13' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move it to the end of the file. |
||
[function.PyList_GetSlice] | ||
added = '3.2' | ||
[function.PyList_Insert] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for 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".