Skip to content

Commit 4929497

Browse files
committed
🏷️ fix stubtest errors in lib._array_utils_impl
1 parent 08410d5 commit 4929497

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

.mypyignore-todo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ numpy._pyinstaller.hook-numpy
1515
numpy.ctypeslib._ctypeslib
1616
numpy.fft.helper
1717

18-
numpy.lib.(_array_utils_impl|array_utils).normalize_axis_tuple
1918
numpy.lib._iotools.NameValidator.defaultdeletechars
2019
numpy.lib.format.open_memmap
2120
numpy.lib.format.read_array(_header_(1|2)_0)?
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
from collections.abc import Iterable
2-
from typing import Any
3-
4-
import numpy as np
5-
import numpy.typing as npt
1+
from collections.abc import Iterable, Mapping
2+
from typing import Any, Protocol, type_check_only
63

74
__all__ = ["byte_bounds", "normalize_axis_index", "normalize_axis_tuple"]
85

6+
###
7+
8+
@type_check_only
9+
class _HasSizeAndArrayInterface(Protocol):
10+
@property
11+
def size(self, /) -> int: ...
12+
@property # `TypedDict` cannot be used because it rejects `dict[str, Any]`
13+
def __array_interface__(self, /) -> Mapping[str, Any]: ...
14+
15+
###
16+
917
# NOTE: In practice `byte_bounds` can (potentially) take any object
1018
# implementing the `__array_interface__` protocol. The caveat is
1119
# that certain keys, marked as optional in the spec, must be present for
1220
# `byte_bounds`. This concerns `"strides"` and `"data"`.
13-
def byte_bounds(a: np.generic | npt.NDArray[Any]) -> tuple[int, int]: ...
14-
def normalize_axis_index(axis: int = ..., ndim: int = ..., msg_prefix: str | None = ...) -> int: ...
21+
def byte_bounds(a: _HasSizeAndArrayInterface) -> tuple[int, int]: ...
22+
23+
###
24+
def normalize_axis_index(axis: int, ndim: int, msg_prefix: str | None = None) -> int: ...
1525
def normalize_axis_tuple(
1626
axis: int | Iterable[int],
17-
ndim: int = ...,
18-
argname: str | None = ...,
19-
allow_duplicate: bool | None = ...,
20-
) -> tuple[int, int]: ...
27+
ndim: int,
28+
argname: str | None = None,
29+
allow_duplicate: bool = False,
30+
) -> tuple[int, ...]: ...

0 commit comments

Comments
 (0)