Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12364e3

Browse files
authored
MAINT: bump mypy to 1.14.1 (#28089)
* MAINT: bump `mypy` to `1.14.1` * TYP: fix new `mypy==1.14.1` type-test errors * TYP: backport `collections.abc.Buffer` for `npt.ArrayLike` on `python<3.11`
1 parent bba6256 commit 12364e3

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- hypothesis
2626
# For type annotations
2727
- typing_extensions>=4.2.0 # needed for python < 3.10
28-
- mypy=1.13.0
28+
- mypy=1.14.1
2929
- orjson # makes mypy faster
3030
# For building docs
3131
- sphinx>=4.5.0

numpy/_typing/_array_like.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ def __array_function__(
8787
)
8888

8989
if sys.version_info >= (3, 12):
90-
from collections.abc import Buffer
91-
92-
ArrayLike: TypeAlias = Buffer | _DualArrayLike[
93-
dtype[Any],
94-
bool | int | float | complex | str | bytes,
95-
]
90+
from collections.abc import Buffer as _Buffer
9691
else:
97-
ArrayLike: TypeAlias = _DualArrayLike[
98-
dtype[Any],
99-
bool | int | float | complex | str | bytes,
100-
]
92+
@runtime_checkable
93+
class _Buffer(Protocol):
94+
def __buffer__(self, flags: int, /) -> memoryview: ...
95+
96+
ArrayLike: TypeAlias = _Buffer | _DualArrayLike[
97+
dtype[Any],
98+
bool | int | float | complex | str | bytes,
99+
]
101100

102101
# `ArrayLike<X>_co`: array-like objects that can be coerced into `X`
103102
# given the casting rules `same_kind`

numpy/typing/tests/data/reveal/index_tricks.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ assert_type(np.mgrid[1:1:2, None:10], npt.NDArray[Any])
5858
assert_type(np.ogrid[1:1:2], tuple[npt.NDArray[Any], ...])
5959
assert_type(np.ogrid[1:1:2, None:10], tuple[npt.NDArray[Any], ...])
6060

61-
assert_type(np.index_exp[0:1], tuple[slice])
62-
assert_type(np.index_exp[0:1, None:3], tuple[slice, slice])
63-
assert_type(np.index_exp[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, EllipsisType, list[int]])
61+
assert_type(np.index_exp[0:1], tuple[slice[int, int, None]])
62+
assert_type(np.index_exp[0:1, None:3], tuple[slice[int, int, None], slice[None, int, None]])
63+
assert_type(np.index_exp[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice[int, int, None], EllipsisType, list[int]])
6464

65-
assert_type(np.s_[0:1], slice)
66-
assert_type(np.s_[0:1, None:3], tuple[slice, slice])
67-
assert_type(np.s_[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, EllipsisType, list[int]])
65+
assert_type(np.s_[0:1], slice[int, int, None])
66+
assert_type(np.s_[0:1, None:3], tuple[slice[int, int, None], slice[None, int, None]])
67+
assert_type(np.s_[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice[int, int, None], EllipsisType, list[int]])
6868

6969
assert_type(np.ix_(AR_LIKE_b), tuple[npt.NDArray[np.bool], ...])
7070
assert_type(np.ix_(AR_LIKE_i, AR_LIKE_f), tuple[npt.NDArray[np.float64], ...])

requirements/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cffi; python_version < '3.10'
1515
# For testing types. Notes on the restrictions:
1616
# - Mypy relies on C API features not present in PyPy
1717
# NOTE: Keep mypy in sync with environment.yml
18-
mypy==1.13.0; platform_python_implementation != "PyPy"
18+
mypy==1.14.1; platform_python_implementation != "PyPy"
1919
typing_extensions>=4.2.0
2020
# for optional f2py encoding detection
2121
charset-normalizer

0 commit comments

Comments
 (0)