py/objarray: Allow extending array with any iterable.

As suggested by @dpgeorge, factor out part of array_construct to allow it
to be used for construction & extension.

Note that extending with a known-length list (or tuple) goes through the
slow path of calling array_extend once per element.

Fixes issue #7408.

Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler
2025-06-01 19:19:51 +02:00
committed by Damien George
parent c1629dc2ff
commit 0a98f3a911
2 changed files with 24 additions and 13 deletions

View File

@@ -14,3 +14,9 @@ print(a1)
a1.extend(array.array('I', [5]))
print(a1)
a1.extend([6, 7])
print(a1)
a1.extend(i for i in (8, 9))
print(a1)