Skip to content

Commit 158316d

Browse files
committed
🎨 optype.io simplifications
1 parent 16b7fd2 commit 158316d

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

‎scipy-stubs/sparse/_matrix_io.pyi

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33
import optype as op
44
from ._bsr import bsr_array, bsr_matrix
@@ -10,12 +10,8 @@ from ._dia import dia_array, dia_matrix
1010

1111
__all__ = ["load_npz", "save_npz"]
1212

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
1915

2016
@type_check_only
2117
class _CanReadAndSeekBytes(Protocol):
@@ -26,25 +22,9 @@ class _CanReadAndSeekBytes(Protocol):
2622
class _PickleKwargs(TypedDict):
2723
allow_pickle: Literal[False]
2824

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-
4525
###
4626

4727
PICKLE_KWARGS: Final[_PickleKwargs] = ...
4828

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

Comments
 (0)