Skip to content

Commit 5b89c55

Browse files
committed
WIP
1 parent 63b319f commit 5b89c55

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/array_api_extra/_lib/_utils/_helpers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import math
77
import pickle
88
from collections.abc import Generator, Iterable
9-
from types import ModuleType
9+
from types import ModuleType, NoneType
1010
from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast
1111

1212
from . import _compat
@@ -319,6 +319,12 @@ def capabilities(xp: ModuleType) -> dict[str, int]:
319319
return out
320320

321321

322+
_BASIC_TYPES = frozenset((
323+
NoneType, bool, int, float, complex, str, bytes, bytearray,
324+
list, tuple, dict, set, frozenset, range, slice,
325+
)) # fmt: skip
326+
327+
322328
def pickle_without(
323329
obj: object, cls: type[T] | tuple[type[T], ...] = ()
324330
) -> tuple[bytes, tuple[T, ...], tuple[object, ...]]:
@@ -390,9 +396,12 @@ class Pickler(pickle.Pickler): # numpydoc ignore=GL01,RT01
390396

391397
@override
392398
def persistent_id(self, obj: object) -> object: # pyright: ignore[reportIncompatibleMethodOverride] # numpydoc ignore=GL08
399+
if type(obj) in _BASIC_TYPES: # No subclasses!
400+
return None
401+
393402
id_ = id(obj)
394403
try:
395-
return seen[id_]
404+
return id_, seen[id_]
396405
except KeyError:
397406
pass
398407

0 commit comments

Comments
 (0)