gh-111489: Add PyTuple_FromArray() function (#139691)

This commit is contained in:
Victor Stinner 2025-10-10 08:54:12 +02:00 committed by GitHub
parent 8f14bddeae
commit e31c22dbf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 76 additions and 2 deletions

View file

@ -62,6 +62,28 @@ def test_tuple_new(self):
self.assertRaises(SystemError, tuple_new, PY_SSIZE_T_MIN)
self.assertRaises(MemoryError, tuple_new, PY_SSIZE_T_MAX)
def test_tuple_fromarray(self):
# Test PyTuple_FromArray()
tuple_fromarray = _testcapi.tuple_fromarray
tup = tuple([i] for i in range(5))
copy = tuple_fromarray(tup)
self.assertEqual(copy, tup)
tup = ()
copy = tuple_fromarray(tup)
self.assertIs(copy, tup)
copy = tuple_fromarray(NULL, 0)
self.assertIs(copy, ())
with self.assertRaises(SystemError):
tuple_fromarray(NULL, -1)
with self.assertRaises(SystemError):
tuple_fromarray(NULL, PY_SSIZE_T_MIN)
with self.assertRaises(MemoryError):
tuple_fromarray(NULL, PY_SSIZE_T_MAX)
def test_tuple_pack(self):
# Test PyTuple_Pack()
pack = _testlimitedcapi.tuple_pack