Skip to content

Commit 6b42b7f

Browse files
committed
fixes
1 parent b034e94 commit 6b42b7f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/array_api_extra/_lib/_utils/_helpers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ def _expand() -> object: # numpydoc ignore=RT01
330330
-----
331331
This function must be global in order to be picklable.
332332
"""
333-
return next(_repacking_objects.get())
333+
try:
334+
return next(_repacking_objects.get())
335+
except StopIteration:
336+
msg = "Not enough objects to repack"
337+
raise ValueError(msg) from None
334338

335339

336340
def pickle_without(obj: object, *classes: type[T]) -> tuple[bytes, list[T]]:
@@ -390,9 +394,16 @@ def reduce(x: T) -> tuple[Callable[[], object], tuple[()]]: # numpydoc ignore=G
390394

391395
f = io.BytesIO()
392396
p = pickle.Pickler(f)
397+
398+
# Override the reducer for the given classes and all their
399+
# subclasses (recursively).
393400
p.dispatch_table = copyreg.dispatch_table.copy()
394-
for cls in classes:
401+
subclasses = list(classes)
402+
while subclasses:
403+
cls = subclasses.pop()
395404
p.dispatch_table[cls] = reduce
405+
subclasses.extend(cls.__subclasses__())
406+
396407
p.dump(obj)
397408

398409
return f.getvalue(), extracted

0 commit comments

Comments
 (0)