-
-
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-111489: Add PyList_FromArrayMoveRef() function #112975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -342,3 +342,11 @@ def test_list_extend(self): | |||||
|
||||||
# CRASHES list_extend(NULL, []) | ||||||
# CRASHES list_extend([], NULL) | ||||||
|
||||||
def test_list_fromarraymoveref(self): | ||||||
# Test PyList_FromArrayMoveRef() | ||||||
list_fromarraymoveref = _testcapi.list_fromarraymoveref | ||||||
|
||||||
lst = [object() for _ in range(5)] | ||||||
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. I would use the following example:
Suggested change
Better repr. 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. First, I used I don't think that repr is important here, the test is not supposed to fail :-) |
||||||
copy = list_fromarraymoveref(lst) | ||||||
self.assertEqual(copy, lst) | ||||||
Comment on lines
+351
to
+352
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. Test also with zero and negative size. with too large size (causing MemoryError or OverflowError), with array=NULL, and with NULLs in the array. We should know what cases raise exceptions, what cases crash and what cases are valid, and how errors are handled. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
from test.support import import_helper | ||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class CAPITest(unittest.TestCase): | ||
def test_tuple_fromarray(self): | ||
# Test PyTuple_FromArray() | ||
tuple_fromarray = _testcapi.tuple_fromarraymoveref | ||
|
||
tup = tuple(object() for _ in range(5)) | ||
copy = tuple_fromarray(tup) | ||
self.assertEqual(copy, tup) | ||
|
||
def test_tuple_fromarraymoveref(self): | ||
# Test PyTuple_FromArrayMoveRef() | ||
tuple_fromarraymoveref = _testcapi.tuple_fromarraymoveref | ||
|
||
tup = tuple(object() for _ in range(5)) | ||
copy = tuple_fromarraymoveref(tup) | ||
self.assertEqual(copy, tup) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Add new functions to create :class:`tuple` and :class:`list` from arrays: | ||
|
||
* :c:func:`PyTuple_FromArray`. | ||
* :c:func:`PyTuple_FromArrayMoveRef`. | ||
* :c:func:`PyList_FromArrayMoveRef`. | ||
|
||
Patch by Victor Stinner. |
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.