1
- from typing import Final , Literal , Protocol , TypeAlias , TypedDict , TypeVar , overload , type_check_only
1
+ from typing import Final , Literal , Protocol , TypeAlias , TypedDict , type_check_only
2
2
3
3
import optype as op
4
4
from ._bsr import bsr_array , bsr_matrix
@@ -10,12 +10,8 @@ from ._dia import dia_array, dia_matrix
10
10
11
11
__all__ = ["load_npz" , "save_npz" ]
12
12
13
- _StrOrBytesT = TypeVar ("_StrOrBytesT" , bound = bytes | str , default = bytes | str )
14
- _StrOrBytesT_co = TypeVar ("_StrOrBytesT_co" , bound = bytes | str , default = bytes | str , covariant = True )
15
-
16
- @type_check_only
17
- class _CanWriteBytes (Protocol ):
18
- def write (self , s : bytes , / ) -> object : ...
13
+ _DataArrayOut : TypeAlias = bsr_array | coo_array | csc_array | csr_array | dia_array
14
+ _DataMatrixOut : TypeAlias = bsr_matrix | coo_matrix | csc_matrix | csr_matrix | dia_matrix
19
15
20
16
@type_check_only
21
17
class _CanReadAndSeekBytes (Protocol ):
@@ -26,25 +22,9 @@ class _CanReadAndSeekBytes(Protocol):
26
22
class _PickleKwargs (TypedDict ):
27
23
allow_pickle : Literal [False ]
28
24
29
- # A superior version of `os.PathLike` that's actually valid:
30
- # Never parametrize generic types with "a TypeVar with constraints"!
31
- @type_check_only
32
- class _CanFSPath (Protocol [_StrOrBytesT_co ]):
33
- @overload
34
- def __fspath__ (self : _CanFSPath [str ], / ) -> str : ...
35
- @overload
36
- def __fspath__ (self : _CanFSPath [bytes ], / ) -> bytes : ...
37
- @overload
38
- def __fspath__ (self : _CanFSPath [bytes | str ], / ) -> bytes | str : ...
39
-
40
- _ToPath : TypeAlias = _StrOrBytesT | _CanFSPath [_StrOrBytesT ]
41
-
42
- _DataArrayOut : TypeAlias = bsr_array | coo_array | csc_array | csr_array | dia_array
43
- _DataMatrixOut : TypeAlias = bsr_matrix | coo_matrix | csc_matrix | csr_matrix | dia_matrix
44
-
45
25
###
46
26
47
27
PICKLE_KWARGS : Final [_PickleKwargs ] = ...
48
28
49
- def load_npz (file : _ToPath | _CanReadAndSeekBytes ) -> _DataArrayOut | _DataMatrixOut : ...
50
- def save_npz (file : _ToPath [str ] | _CanWriteBytes , matrix : _data_matrix , compressed : op .CanBool = True ) -> None : ...
29
+ def load_npz (file : op . io . ToPath | _CanReadAndSeekBytes ) -> _DataArrayOut | _DataMatrixOut : ...
30
+ def save_npz (file : op . io . ToPath [str ] | op . io . CanWrite [ bytes ] , matrix : _data_matrix , compressed : op .CanBool = True ) -> None : ...
0 commit comments