File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 25
25
26
26
See :mod:`nibabel.tests.test_proxy_api` for proxy API conformance checks.
27
27
"""
28
+ import typing as ty
28
29
import warnings
29
30
from contextlib import contextmanager
30
31
from threading import RLock
31
32
32
33
import numpy as np
34
+ import numpy .typing as npt
33
35
34
36
from . import openers
35
37
from .fileslice import canonical_slicers , fileslice
53
55
KEEP_FILE_OPEN_DEFAULT = False
54
56
55
57
56
- class ArrayProxy :
58
+ @ty .runtime_checkable
59
+ class ArrayLike (ty .Protocol ):
60
+ """Protocol for numpy ndarray-like objects
61
+
62
+ This is more stringent than :class:`numpy.typing.ArrayLike`, but guarantees
63
+ access to shape, ndim and slicing.
64
+ """
65
+
66
+ shape : tuple [int , ...]
67
+ ndim : int
68
+
69
+ def __array__ (self , dtype : npt .DTypeLike | None = None , / ) -> npt .NDArray :
70
+ ...
71
+
72
+ def __getitem__ (self , key , / ) -> npt .NDArray :
73
+ ...
74
+
75
+
76
+ class ArrayProxy (ArrayLike ):
57
77
"""Class to act as proxy for the array that can be read from a file
58
78
59
79
The array proxy allows us to freeze the passed fileobj and header such that
You can’t perform that action at this time.
0 commit comments