8000 TYP: update the type-tests for gradual shape-type defaults · numpy/numpy@f5ae1f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5ae1f7

Browse files
committed
TYP: update the type-tests for gradual shape-type defaults
1 parent 12b741e commit f5ae1f7

15 files changed

+132
-124
lines changed

numpy/typing/tests/data/fail/chararray.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from typing import Any
12
import numpy as np
23

3-
AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
4-
AR_S: np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]]
4+
AR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]
5+
AR_S: np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]]
56

67
AR_S.encode() # type: ignore[misc]
78
AR_U.decode() # type: ignore[misc]

numpy/typing/tests/data/pass/recfunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_stack_arrays() -> None:
143143
zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
144144
assert_type(
145145
rfn.stack_arrays((z, zz)),
146-
np.ma.MaskedArray[tuple[int, ...], np.dtype[np.void]],
146+
np.ma.MaskedArray[tuple[Any, ...], np.dtype[np.void]],
147147
)
148148

149149

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ assert_type(np.empty([1, 5, 6], dtype='c16'), npt.NDArray[Any])
5151
assert_type(np.empty(mixed_shape), npt.NDArray[np.float64])
5252

5353
assert_type(np.concatenate(A), npt.NDArray[np.float64])
54-
assert_type(np.concatenate([A, A]), npt.NDArray[Any])
54+
assert_type(np.concatenate([A, A]), Any) # pyright correctly infers this as NDArray[float64]
5555
assert_type(np.concatenate([[1], A]), npt.NDArray[Any])
5656
assert_type(np.concatenate([[1], [1]]), npt.NDArray[Any])
5757
assert_type(np.concatenate((A, A)), npt.NDArray[np.float64])
@@ -220,22 +220,22 @@ assert_type(np.atleast_3d(A), npt.NDArray[np.float64])
220220
assert_type(np.atleast_3d(A, A), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]])
221221
assert_type(np.atleast_3d(A, A, A), tuple[npt.NDArray[np.float64], ...])
222222

223-
assert_type(np.vstack([A, A]), npt.NDArray[np.float64])
223+
assert_type(np.vstack([A, A]), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
224224
assert_type(np.vstack([A, A], dtype=np.float32), npt.NDArray[np.float32])
225225
assert_type(np.vstack([A, C]), npt.NDArray[Any])
226226
assert_type(np.vstack([C, C]), npt.NDArray[Any])
227227

228-
assert_type(np.hstack([A, A]), npt.NDArray[np.float64])
228+
assert_type(np.hstack([A, A]), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
229229
assert_type(np.hstack([A, A], dtype=np.float32), npt.NDArray[np.float32])
230230

231-
assert_type(np.stack([A, A]), npt.NDArray[np.float64])
231+
assert_type(np.stack([A, A]), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
232232
assert_type(np.stack([A, A], dtype=np.float32), npt.NDArray[np.float32])
233233
assert_type(np.stack([A, C]), npt.NDArray[Any])
234234
assert_type(np.stack([C, C]), npt.NDArray[Any])
235-
assert_type(np.stack([A, A], axis=0), npt.NDArray[np.float64])
235+
assert_type(np.stack([A, A], axis=0), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
236236
assert_type(np.stack([A, A], out=B), SubClass[np.float64])
237237

238-
assert_type(np.block([[A, A], [A, A]]), npt.NDArray[Any])
238+
assert_type(np.block([[A, A], [A, A]]), npt.NDArray[Any]) # pyright correctly infers this as NDArray[float64]
239239
assert_type(np.block(C), npt.NDArray[Any])
240240

241241
if sys.version_info >= (3, 12):

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ assert_type(ar_iter.buf_size, int | None)
1212
assert_type(ar_iter.start, list[int])
1313
assert_type(ar_iter.stop, list[int])
1414
assert_type(ar_iter.step, list[int])
15-
assert_type(ar_iter.shape, tuple[int, ...])
15+
assert_type(ar_iter.shape, tuple[Any, ...])
1616
assert_type(ar_iter.flat, Generator[np.int64, None, None])
1717

1818
assert_type(ar_iter.__array__(), npt.NDArray[np.int64])
1919

2020
for i in ar_iter:
2121
assert_type(i, npt.NDArray[np.int64])
2222

23-
assert_type(ar_iter[0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
24-
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
25-
assert_type(ar_iter[:], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
26-
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
27-
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
23+
assert_type(ar_iter[0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
24+
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
25+
assert_type(ar_iter[:], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
26+
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
27+
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import numpy as np
44
import numpy._typing as np_t
55
import numpy.typing as npt
66

7+
AR_T_alias: TypeAlias = np.ndarray[np_t._AnyShape, np.dtypes.StringDType]
8+
AR_TU_alias: TypeAlias = AR_T_alias | npt.NDArray[np.str_]
9+
710
AR_U: npt.NDArray[np.str_]
811
AR_S: npt.NDArray[np.bytes_]
9-
AR_T: np.ndarray[np_t._Shape, np.dtypes.StringDType]
10-
11-
AR_T_alias: TypeAlias = np.ndarray[np_t._Shape, np.dtypes.StringDType]
12-
AR_TU_alias: TypeAlias = AR_T_alias | npt.NDArray[np.str_]
12+
AR_T: AR_T_alias
1313

1414
assert_type(np.char.equal(AR_U, AR_U), npt.NDArray[np.bool])
1515
assert_type(np.char.equal(AR_S, AR_S), npt.NDArray[np.bool])
@@ -203,16 +203,16 @@ assert_type(np.char.translate(AR_U, ""), npt.NDArray[np.str_])
203203
assert_type(np.char.translate(AR_S, ""), npt.NDArray[np.bytes_])
204204
assert_type(np.char.translate(AR_T, ""), AR_T_alias)
205205

206-
assert_type(np.char.array(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
207-
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
208-
assert_type(np.char.array("bob", copy=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
209-
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
210-
assert_type(np.char.array(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
211-
assert_type(np.char.array(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
212-
213-
assert_type(np.char.asarray(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
214-
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
215-
assert_type(np.char.asarray("bob"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
216-
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
217-
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
218-
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
206+
assert_type(np.char.array(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
207+
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
208+
assert_type(np.char.array("bob", copy=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
209+
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
210+
assert_type(np.char.array(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
211+
assert_type(np.char.array(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
212+
213+
assert_type(np.char.asarray(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
214+
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
215+
assert_type(np.char.asarray("bob"), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
216+
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
217+
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
218+
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])

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

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from typing import Any, assert_type
1+
from typing import Any, TypeAlias, assert_type
22

33
import numpy as np
44
import numpy.typing as npt
55

6-
AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
7-
AR_S: np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]]
6+
_BytesCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]]
7+
_StrCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]
8+
9+
AR_U: _StrCharArray
10+
AR_S: _BytesCharArray
811

912
assert_type(AR_U == AR_U, npt.NDArray[np.bool])
1013
assert_type(AR_S == AR_S, npt.NDArray[np.bool])
@@ -24,46 +27,46 @@ assert_type(AR_S > AR_S, npt.NDArray[np.bool])
2427
assert_type(AR_U < AR_U, npt.NDArray[np.bool])
2528
assert_type(AR_S < AR_S, npt.NDArray[np.bool])
2629

27-
assert_type(AR_U * 5, np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
28-
assert_type(AR_S * [5], np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
30+
assert_type(AR_U * 5, _StrCharArray)
31+
assert_type(AR_S * [5], _BytesCharArray)
2932

30-
assert_type(AR_U % "test", np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
31-
assert_type(AR_S % b"test", np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
33+
assert_type(AR_U % "test", _StrCharArray)
34+
assert_type(AR_S % b"test", _BytesCharArray)
3235

33-
assert_type(AR_U.capitalize(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
34-
assert_type(AR_S.capitalize(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
36+
assert_type(AR_U.capitalize(), _StrCharArray)
37+
assert_type(AR_S.capitalize(), _BytesCharArray)
3538

36-
assert_type(AR_U.center(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
37-
assert_type(AR_S.center([2, 3, 4], b"a"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
39+
assert_type(AR_U.center(5), _StrCharArray)
40+
assert_type(AR_S.center([2, 3, 4], b"a"), _BytesCharArray)
3841

39-
assert_type(AR_U.encode(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
40-
assert_type(AR_S.decode(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
42+
assert_type(AR_U.encode(), _BytesCharArray)
43+
assert_type(AR_S.decode(), _StrCharArray)
4144

42-
assert_type(AR_U.expandtabs(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
43-
assert_type(AR_S.expandtabs(tabsize=4), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
45+
assert_type(AR_U.expandtabs(), _StrCharArray)
46+
assert_type(AR_S.expandtabs(tabsize=4), _BytesCharArray)
4447

45-
assert_type(AR_U.join("_"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
46-
assert_type(AR_S.join([b"_", b""]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
48+
assert_type(AR_U.join("_"), _StrCharArray)
49+
assert_type(AR_S.join([b"_", b""]), _BytesCharArray)
4750

48-
assert_type(AR_U.ljust(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
49-
assert_type(AR_S.ljust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
50-
assert_type(AR_U.rjust(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
51-
assert_type(AR_S.rjust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
51+
assert_type(AR_U.ljust(5), _StrCharArray)
52+
assert_type(AR_S.ljust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray)
53+
assert_type(AR_U.rjust(5), _StrCharArray)
54+
assert_type(AR_S.rjust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray)
5255

53-
assert_type(AR_U.lstrip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
54-
assert_type(AR_S.lstrip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
55-
assert_type(AR_U.rstrip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
56-
assert_type(AR_S.rstrip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
57-
assert_type(AR_U.strip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
58-
assert_type(AR_S.strip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
56+
assert_type(AR_U.lstrip(), _StrCharArray)
57+
assert_type(AR_S.lstrip(chars=b"_"), _BytesCharArray)
58+
assert_type(AR_U.rstrip(), _StrCharArray)
59+
assert_type(AR_S.rstrip(chars=b"_"), _BytesCharArray)
60+
assert_type(AR_U.strip(), _StrCharArray)
61+
assert_type(AR_S.strip(chars=b"_"), _BytesCharArray)
5962

60-
assert_type(AR_U.partition("\n"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
61-
assert_type(AR_S.partition([b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
62-
assert_type(AR_U.rpartition("\n"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
63-
assert_type(AR_S.rpartition([b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
63+
assert_type(AR_U.partition("\n"), _StrCharArray)
64+
assert_type(AR_S.partition([b"a", b"b", b"c"]), _BytesCharArray)
65+
assert_type(AR_U.rpartition("\n"), _StrCharArray)
66+
assert_type(AR_S.rpartition([b"a", b"b", b"c"]), _BytesCharArray)
6467

65-
assert_type(AR_U.replace("_", "-"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
66-
assert_type(AR_S.replace([b"_", b""], [b"a", b"b"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
68+
assert_type(AR_U.replace("_", "-"), _StrCharArray)
69+
assert_type(AR_S.replace([b"_", b""], [b"a", b"b"]), _BytesCharArray)
6770

6871
assert_type(AR_U.split("_"), npt.NDArray[np.object_])
6972
assert_type(AR_S.split(maxsplit=[1, 2, 3]), npt.NDArray[np.object_])
@@ -73,17 +76,17 @@ assert_type(AR_S.rsplit(maxsplit=[1, 2, 3]), npt.NDArray[np.object_])
7376
assert_type(AR_U.splitlines(), npt.NDArray[np.object_])
7477
assert_type(AR_S.splitlines(keepends=[True, True, False]), npt.NDArray[np.object_])
7578

76-
assert_type(AR_U.swapcase(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
77-
assert_type(AR_S.swapcase(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
79+
assert_type(AR_U.swapcase(), _StrCharArray)
80+
assert_type(AR_S.swapcase(), _BytesCharArray)
7881< 10000 code class="diff-text syntax-highlighted-line">

79-
assert_type(AR_U.title(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
80-
assert_type(AR_S.title(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
82+
assert_type(AR_U.title(), _StrCharArray)
83+
assert_type(AR_S.title(), _BytesCharArray)
8184

82-
assert_type(AR_U.upper(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
83-
assert_type(AR_S.upper(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
85+
assert_type(AR_U.upper(), _StrCharArray)
86+
assert_type(AR_S.upper(), _BytesCharArray)
8487

85-
assert_type(AR_U.zfill(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
86-
assert_type(AR_S.zfill([2, 3, 4]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
88+
assert_type(AR_U.zfill(5), _StrCharArray)
89+
assert_type(AR_S.zfill([2, 3, 4]), _BytesCharArray)
8790

8891
assert_type(AR_U.count("a", start=[1, 2, 3]), npt.NDArray[np.int_])
8992
assert_type(AR_S.count([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ assert_type(np.dtype("|T"), StringDType)
108108

109109
# Methods and attributes
110110
assert_type(dtype_U.base, np.dtype)
111-
assert_type(dtype_U.subdtype, tuple[np.dtype, tuple[int, ...]] | None)
111+
assert_type(dtype_U.subdtype, tuple[np.dtype, tuple[Any, ...]] | None)
112112
assert_type(dtype_U.newbyteorder(), np.dtype[np.str_])
113113
assert_type(dtype_U.type, type[np.str_])
114114
assert_type(dtype_U.name, LiteralString)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ AR_i8: npt.NDArray[np.int64]
1616
AR_O: npt.NDArray[np.object_]
1717
AR_subclass: NDArraySubclass
1818
AR_m: npt.NDArray[np.timedelta64]
19-
AR_0d: np.ndarray[tuple[()], np.dtype]
20-
AR_1d: np.ndarray[tuple[int], np.dtype]
21-
AR_nd: np.ndarray[tuple[int, ...], np.dtype]
19+
AR_0d: np.ndarray[tuple[()]]
20+
AR_1d: np.ndarray[tuple[int]]
21+
AR_nd: np.ndarray
2222

2323
b: np.bool
2424
f4: np.float32
@@ -136,9 +136,9 @@ assert_type(np.shape(b), tuple[()])
136136
assert_type(np.shape(f), tuple[()])
137137
assert_type(np.shape([1]), tuple[int])
138138
assert_type(np.shape([[2]]), tuple[int, int])
139-
assert_type(np.shape([[[3]]]), tuple[int, ...])
140-
assert_type(np.shape(AR_b), tuple[int, ...])
141-
assert_type(np.shape(AR_nd), tuple[int, ...])
139+
assert_type(np.shape([[[3]]]), tuple[Any, ...])
140+
assert_type(np.shape(AR_b), tuple[Any, ...])
141+
assert_type(np.shape(AR_nd), tuple[Any, ...])
142142
# these fail on mypy, but it works as expected with pyright/pylance
143143
# assert_type(np.shape(AR_0d), tuple[()])
144144
# assert_type(np.shape(AR_1d), tuple[int])

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ assert_type(np.ndenumerate(AR_LIKE_f), np.ndenumerate[np.float64])
1818
assert_type(np.ndenumerate(AR_LIKE_U), np.ndenumerate[np.str_])
1919
assert_type(np.ndenumerate(AR_LIKE_O), np.ndenumerate[Any])
2020

21-
assert_type(next(np.ndenumerate(AR_i8)), tuple[tuple[int, ...], np.int64])
22-
assert_type(next(np.ndenumerate(AR_LIKE_f)), tuple[tuple[int, ...], np.float64])
23-
assert_type(next(np.ndenumerate(AR_LIKE_U)), tuple[tuple[int, ...], np.str_])
24-
assert_type(next(np.ndenumerate(AR_LIKE_O)), tuple[tuple[int, ...], Any])
21+
assert_type(next(np.ndenumerate(AR_i8)), tuple[tuple[Any, ...], np.int64])
22+
assert_type(next(np.ndenumerate(AR_LIKE_f)), tuple[tuple[Any, ...], np.float64])
23+
assert_type(next(np.ndenumerate(AR_LIKE_U)), tuple[tuple[Any, ...], np.str_])
24+
assert_type(next(np.ndenumerate(AR_LIKE_O)), tuple[tuple[Any, ...], Any])
2525

2626
assert_type(iter(np.ndenumerate(AR_i8)), np.ndenumerate[np.int64])
2727
assert_type(iter(np.ndenumerate(AR_LIKE_f)), np.ndenumerate[np.float64])
@@ -31,7 +31,7 @@ assert_type(iter(np.ndenumerate(AR_LIKE_O)), np.ndenumerate[Any])
3131
assert_type(np.ndindex(1, 2, 3), np.ndindex)
3232
assert_type(np.ndindex((1, 2, 3)), np.ndindex)
3333
assert_type(iter(np.ndindex(1, 2, 3)), np.ndindex)
34-
assert_type(next(np.ndindex(1, 2, 3)), tuple[int, ...])
34+
assert_type(next(np.ndindex(1, 2, 3)), tuple[Any, ...])
3535

3636
assert_type(np.unravel_index([22, 41, 37], (7, 6)), tuple[npt.NDArray[np.intp], ...])
3737
assert_type(np.unravel_index([31, 41, 13], (7, 6), order="F"), tuple[npt.NDArray[np.intp], ...])

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AR_M: npt.NDArray[np.datetime64]
2020
AR_O: npt.NDArray[np.object_]
2121
AR_b: npt.NDArray[np.bool]
2222
AR_U: npt.NDArray[np.str_]
23-
CHAR_AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
23+
CHAR_AR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]
2424

2525
AR_b_list: list[npt.NDArray[np.bool]]
2626

@@ -81,9 +81,9 @@ assert_type(np.select([AR_f8], [AR_f8]), npt.NDArray[Any])
8181

8282
assert_type(np.copy(AR_LIKE_f8), npt.NDArray[Any])
8383
assert_type(np.copy(AR_U), npt.NDArray[np.str_])
84-
assert_type(np.copy(CHAR_AR_U), npt.NDArray[np.str_])
85-
assert_type(np.copy(CHAR_AR_U, "K", subok=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
86-
assert_type(np.copy(CHAR_AR_U, subok=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
84+
assert_type(np.copy(CHAR_AR_U), np.ndarray[Any, Any]) # pyright correctly infers `NDArray[str_]`
85+
assert_type(np.copy(CHAR_AR_U, "K", subok=True), np.char.chararray[tuple[Any, ...], np.dtype[np.str_]])
86+
assert_type(np.copy(CHAR_AR_U, subok=True), np.char.chararray[tuple[Any, ...], np.dtype[np.str_]])
8787

8888
assert_type(np.gradient(AR_f8, axis=None), Any)
8989
assert_type(np.gradient(AR_LIKE_f8, edge_order=2), Any)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from datetime import datetime, timedelta
21
from typing import Any, Literal, TypeAlias, TypeVar, assert_type
32

43
import numpy as np
54
from numpy import dtype, generic
6-
from numpy._typing import NDArray, _Shape
5+
from numpy._typing import NDArray, _AnyShape
76

87
_ScalarT = TypeVar("_ScalarT", bound=generic)
9-
MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, dtype[_ScalarT]]
8+
MaskedArray: TypeAlias = np.ma.MaskedArray[_AnyShape, dtype[_ScalarT]]
109
_Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]
1110

1211
class MaskedArraySubclass(MaskedArray[np.complex128]): ...

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ assert_type(b_f8.iters, tuple[np.flatiter[Any], ...])
4848
assert_type(b_f8.nd, int)
4949
assert_type(b_f8.ndim, int)
5050
assert_type(b_f8.numiter, int)
51-
assert_type(b_f8.shape, tuple[int, ...])
51+
assert_type(b_f8.shape, tuple[Any, ...])
5252
assert_type(b_f8.size, int)
5353

5454
assert_type(next(b_i8_f8_f8), tuple[Any, ...])
@@ -58,7 +58,7 @@ assert_type(b_i8_f8_f8.iters, tuple[np.flatiter[Any], ...])
5858
assert_type(b_i8_f8_f8.nd, int)
5959
assert_type(b_i8_f8_f8.ndim, int)
6060
assert_type(b_i8_f8_f8.numiter, int)
61-
assert_type(b_i8_f8_f8.shape, tuple[int, ...])
61+
assert_type(b_i8_f8_f8.shape, tuple[Any, ...])
6262
assert_type(b_i8_f8_f8.size, int)
6363

6464
assert_type(np.inner(AR_f8, AR_i8), Any)

0 commit comments

Comments
 (0)
0