Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TYP: Gradual shape type defaults #28982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TYP: update the type-tests for gradual shape-type defaults
  • Loading branch information
jorenham committed May 16, 2025
commit f5ae1f7ea80e4f961af002398dd71d5a632f1944
5 changes: 3 additions & 2 deletions 5 numpy/typing/tests/data/fail/chararray.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any
import numpy as np

AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
AR_S: np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]]
AR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]
AR_S: np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]]

AR_S.encode() # type: ignore[misc]
AR_U.decode() # type: ignore[misc]
Expand Down
2 changes: 1 addition & 1 deletion 2 numpy/typing/tests/data/pass/recfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_stack_arrays() -> None:
zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
assert_type(
rfn.stack_arrays((z, zz)),
np.ma.MaskedArray[tuple[int, ...], np.dtype[np.void]],
np.ma.MaskedArray[tuple[Any, ...], np.dtype[np.void]],
)


Expand Down
12 changes: 6 additions & 6 deletions 12 numpy/typing/tests/data/reveal/array_constructors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ assert_type(np.empty([1, 5, 6], dtype='c16'), npt.NDArray[Any])
assert_type(np.empty(mixed_shape), npt.NDArray[np.float64])

assert_type(np.concatenate(A), npt.NDArray[np.float64])
assert_type(np.concatenate([A, A]), npt.NDArray[Any])
assert_type(np.concatenate([A, A]), Any) # pyright correctly infers this as NDArray[float64]
assert_type(np.concatenate([[1], A]), npt.NDArray[Any])
assert_type(np.concatenate([[1], [1]]), npt.NDArray[Any])
assert_type(np.concatenate((A, A)), npt.NDArray[np.float64])
Expand Down Expand Up @@ -220,22 +220,22 @@ assert_type(np.atleast_3d(A), npt.NDArray[np.float64])
assert_type(np.atleast_3d(A, A), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]])
assert_type(np.atleast_3d(A, A, A), tuple[npt.NDArray[np.float64], ...])

assert_type(np.vstack([A, A]), npt.NDArray[np.float64])
assert_type(np.vstack([A, A]), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
assert_type(np.vstack([A, A], dtype=np.float32), npt.NDArray[np.float32])
assert_type(np.vstack([A, C]), npt.NDArray[Any])
assert_type(np.vstack([C, C]), npt.NDArray[Any])

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

assert_type(np.stack([A, A]), npt.NDArray[np.float64])
assert_type(np.stack([A, A]), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
assert_type(np.stack([A, A], dtype=np.float32), npt.NDArray[np.float32])
assert_type(np.stack([A, C]), npt.NDArray[Any])
assert_type(np.stack([C, C]), npt.NDArray[Any])
assert_type(np.stack([A, A], axis=0), npt.NDArray[np.float64])
assert_type(np.stack([A, A], axis=0), np.ndarray[Any, Any]) # pyright correctly infers this as NDArray[float64]
assert_type(np.stack([A, A], out=B), SubClass[np.float64])

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

if sys.version_info >= (3, 12):
Expand Down
12 changes: 6 additions & 6 deletions 12 numpy/typing/tests/data/reveal/arrayterator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ assert_type(ar_iter.buf_size, int | None)
assert_type(ar_iter.start, list[int])
assert_type(ar_iter.stop, list[int])
assert_type(ar_iter.step, list[int])
assert_type(ar_iter.shape, tuple[int, ...])
assert_type(ar_iter.shape, tuple[Any, ...])
assert_type(ar_iter.flat, Generator[np.int64, None, None])

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

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

assert_type(ar_iter[0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
assert_type(ar_iter[:], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
assert_type(ar_iter[0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
assert_type(ar_iter[:], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]])
34 changes: 17 additions & 17 deletions 34 numpy/typing/tests/data/reveal/char.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import numpy as np
import numpy._typing as np_t
import numpy.typing as npt

AR_T_alias: TypeAlias = np.ndarray[np_t._AnyShape, np.dtypes.StringDType]
AR_TU_alias: TypeAlias = AR_T_alias | npt.NDArray[np.str_]

AR_U: npt.NDArray[np.str_]
AR_S: npt.NDArray[np.bytes_]
AR_T: np.ndarray[np_t._Shape, np.dtypes.StringDType]

AR_T_alias: TypeAlias = np.ndarray[np_t._Shape, np.dtypes.StringDType]
AR_TU_alias: TypeAlias = AR_T_alias | npt.NDArray[np.str_]
AR_T: AR_T_alias

assert_type(np.char.equal(AR_U, AR_U), npt.NDArray[np.bool])
assert_type(np.char.equal(AR_S, AR_S), npt.NDArray[np.bool])
Expand Down Expand Up @@ -203,16 +203,16 @@ assert_type(np.char.translate(AR_U, ""), npt.NDArray[np.str_])
assert_type(np.char.translate(AR_S, ""), npt.NDArray[np.bytes_])
assert_type(np.char.translate(AR_T, ""), AR_T_alias)

assert_type(np.char.array(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.array("bob", copy=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.array(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.array(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])

assert_type(np.char.asarray(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.asarray("bob"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(np.char.array(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.array("bob", copy=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.array(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.array(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])

assert_type(np.char.asarray(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.asarray("bob"), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]])
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]])
85 changes: 44 additions & 41 deletions 85 numpy/typing/tests/data/reveal/chararray.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from typing import Any, assert_type
from typing import Any, TypeAlias, assert_type

import numpy as np
import numpy.typing as npt

AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
AR_S: np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]]
_BytesCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]]
_StrCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]

AR_U: _StrCharArray
AR_S: _BytesCharArray

assert_type(AR_U == AR_U, npt.NDArray[np.bool])
assert_type(AR_S == AR_S, npt.NDArray[np.bool])
Expand All @@ -24,46 +27,46 @@ assert_type(AR_S > AR_S, npt.NDArray[np.bool])
assert_type(AR_U < AR_U, npt.NDArray[np.bool])
assert_type(AR_S < AR_S, npt.NDArray[np.bool])

assert_type(AR_U * 5, np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S * [5], np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U * 5, _StrCharArray)
assert_type(AR_S * [5], _BytesCharArray)

assert_type(AR_U % "test", np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S % b"test", np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U % "test", _StrCharArray)
assert_type(AR_S % b"test", _BytesCharArray)

assert_type(AR_U.capitalize(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.capitalize(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.capitalize(), _StrCharArray)
assert_type(AR_S.capitalize(), _BytesCharArray)

assert_type(AR_U.center(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.center([2, 3, 4], b"a"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.center(5), _StrCharArray)
assert_type(AR_S.center([2, 3, 4], b"a"), _BytesCharArray)

assert_type(AR_U.encode(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_S.decode(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_U.encode(), _BytesCharArray)
assert_type(AR_S.decode(), _StrCharArray)

assert_type(AR_U.expandtabs(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.expandtabs(tabsize=4), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.expandtabs(), _StrCharArray)
assert_type(AR_S.expandtabs(tabsize=4), _BytesCharArray)

assert_type(AR_U.join("_"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.join([b"_", b""]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.join("_"), _StrCharArray)
assert_type(AR_S.join([b"_", b""]), _BytesCharArray)

assert_type(AR_U.ljust(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.ljust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.rjust(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.rjust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.ljust(5), _StrCharArray)
assert_type(AR_S.ljust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray)
assert_type(AR_U.rjust(5), _StrCharArray)
assert_type(AR_S.rjust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray)

assert_type(AR_U.lstrip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.lstrip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.rstrip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.rstrip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.strip(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.strip(chars=b"_"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.lstrip(), _StrCharArray)
assert_type(AR_S.lstrip(chars=b"_"), _BytesCharArray)
assert_type(AR_U.rstrip(), _StrCharArray)
assert_type(AR_S.rstrip(chars=b"_"), _BytesCharArray)
assert_type(AR_U.strip(), _StrCharArray)
assert_type(AR_S.strip(chars=b"_"), _BytesCharArray)

assert_type(AR_U.partition("\n"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.partition([b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.rpartition("\n"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.rpartition([b"a", b"b", b"c"]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.partition("\n"), _StrCharArray)
assert_type(AR_S.partition([b"a", b"b", b"c"]), _BytesCharArray)
assert_type(AR_U.rpartition("\n"), _StrCharArray)
assert_type(AR_S.rpartition([b"a", b"b", b"c"]), _BytesCharArray)

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

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

assert_type(AR_U.swapcase(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.swapcase(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.swapcase(), _StrCharArray)
assert_type(AR_S.swapcase(), _BytesCharArray)

assert_type(AR_U.title(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.title(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.title(), _StrCharArray)
assert_type(AR_S.title(), _BytesCharArray)

assert_type(AR_U.upper(), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.upper(), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.upper(), _StrCharArray)
assert_type(AR_S.upper(), _BytesCharArray)

assert_type(AR_U.zfill(5), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
assert_type(AR_S.zfill([2, 3, 4]), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
assert_type(AR_U.zfill(5), _StrCharArray)
assert_type(AR_S.zfill([2, 3, 4]), _BytesCharArray)

assert_type(AR_U.count("a", start=[1, 2, 3]), npt.NDArray[np.int_])
assert_type(AR_S.count([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
Expand Down
2 changes: 1 addition & 1 deletion 2 numpy/typing/tests/data/reveal/dtype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ assert_type(np.dtype("|T"), StringDType)

# Methods and attributes
assert_type(dtype_U.base, np.dtype)
assert_type(dtype_U.subdtype, tuple[np.dtype, tuple[int, ...]] | None)
assert_type(dtype_U.subdtype, tuple[np.dtype, tuple[Any, ...]] | None)
assert_type(dtype_U.newbyteorder(), np.dtype[np.str_])
assert_type(dtype_U.type, type[np.str_])
assert_type(dtype_U.name, LiteralString)
Expand Down
12 changes: 6 additions & 6 deletions 12 numpy/typing/tests/data/reveal/fromnumeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ AR_i8: npt.NDArray[np.int64]
AR_O: npt.NDArray[np.object_]
AR_subclass: NDArraySubclass
AR_m: npt.NDArray[np.timedelta64]
AR_0d: np.ndarray[tuple[()], np.dtype]
AR_1d: np.ndarray[tuple[int], np.dtype]
AR_nd: np.ndarray[tuple[int, ...], np.dtype]
AR_0d: np.ndarray[tuple[()]]
AR_1d: np.ndarray[tuple[int]]
AR_nd: np.ndarray

b: np.bool
f4: np.float32
Expand Down Expand Up @@ -136,9 +136,9 @@ assert_type(np.shape(b), tuple[()])
assert_type(np.shape(f), tuple[()])
assert_type(np.shape([1]), tuple[int])
assert_type(np.shape([[2]]), tuple[int, int])
assert_type(np.shape([[[3]]]), tuple[int, ...])
assert_type(np.shape(AR_b), tuple[int, ...])
assert_type(np.shape(AR_nd), tuple[int, ...])
assert_type(np.shape([[[3]]]), tuple[Any, ...])
assert_type(np.shape(AR_b), tuple[Any, ...])
assert_type(np.shape(AR_nd), tuple[Any, ...])
# these fail on mypy, but it works as expected with pyright/pylance
# assert_type(np.shape(AR_0d), tuple[()])
# assert_type(np.shape(AR_1d), tuple[int])
Expand Down
10 changes: 5 additions & 5 deletions 10 numpy/typing/tests/data/reveal/index_tricks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ assert_type(np.ndenumerate(AR_LIKE_f), np.ndenumerate[np.float64])
assert_type(np.ndenumerate(AR_LIKE_U), np.ndenumerate[np.str_])
assert_type(np.ndenumerate(AR_LIKE_O), np.ndenumerate[Any])

assert_type(next(np.ndenumerate(AR_i8)), tuple[tuple[int, ...], np.int64])
assert_type(next(np.ndenumerate(AR_LIKE_f)), tuple[tuple[int, ...], np.float64])
assert_type(next(np.ndenumerate(AR_LIKE_U)), tuple[tuple[int, ...], np.str_])
assert_type(next(np.ndenumerate(AR_LIKE_O)), tuple[tuple[int, ...], Any])
assert_type(next(np.ndenumerate(AR_i8)), tuple[tuple[Any, ...], np.int64])
assert_type(next(np.ndenumerate(AR_LIKE_f)), tuple[tuple[Any, ...], np.float64])
assert_type(next(np.ndenumerate(AR_LIKE_U)), tuple[tuple[Any, ...], np.str_])
assert_type(next(np.ndenumerate(AR_LIKE_O)), tuple[tuple[Any, ...], Any])

assert_type(iter(np.ndenumerate(AR_i8)), np.ndenumerate[np.int64])
assert_type(iter(np.ndenumerate(AR_LIKE_f)), np.ndenumerate[np.float64])
Expand All @@ -31,7 +31,7 @@ assert_type(iter(np.ndenumerate(AR_LIKE_O)), np.ndenumerate[Any])
assert_type(np.ndindex(1, 2, 3), np.ndindex)
assert_type(np.ndindex((1, 2, 3)), np.ndindex)
assert_type(iter(np.ndindex(1, 2, 3)), np.ndindex)
assert_type(next(np.ndindex(1, 2, 3)), tuple[int, ...])
assert_type(next(np.ndindex(1, 2, 3)), tuple[Any, ...])

assert_type(np.unravel_index([22, 41, 37], (7, 6)), tuple[npt.NDArray[np.intp], ...])
assert_type(np.unravel_index([31, 41, 13], (7, 6), order="F"), tuple[npt.NDArray[np.intp], ...])
Expand Down
8 changes: 4 additions & 4 deletions 8 numpy/typing/tests/data/reveal/lib_function_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AR_M: npt.NDArray[np.datetime64]
AR_O: npt.NDArray[np.object_]
AR_b: npt.NDArray[np.bool]
AR_U: npt.NDArray[np.str_]
CHAR_AR_U: np.char.chararray[tuple[int, ...], np.dtype[np.str_]]
CHAR_AR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]

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

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

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

assert_type(np.gradient(AR_f8, axis=None), Any)
assert_type(np.gradient(AR_LIKE_f8, edge_order=2), Any)
Expand Down
5 changes: 2 additions & 3 deletions 5 numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime, timedelta
from typing import Any, Literal, TypeAlias, TypeVar, assert_type

import numpy as np
from numpy import dtype, generic
from numpy._typing import NDArray, _Shape
from numpy._typing import NDArray, _AnyShape

_ScalarT = TypeVar("_ScalarT", bound=generic)
MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, dtype[_ScalarT]]
MaskedArray: TypeAlias = np.ma.MaskedArray[_AnyShape, dtype[_ScalarT]]
_Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]

class MaskedArraySubclass(MaskedArray[np.complex128]): ...
Expand Down
4 changes: 2 additions & 2 deletions 4 numpy/typing/tests/data/reveal/multiarray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ assert_type(b_f8.iters, tuple[np.flatiter[Any], ...])
assert_type(b_f8.nd, int)
assert_type(b_f8.ndim, int)
assert_type(b_f8.numiter, int)
assert_type(b_f8.shape, tuple[int, ...])
assert_type(b_f8.shape, tuple[Any, ...])
assert_type(b_f8.size, int)

assert_type(next(b_i8_f8_f8), tuple[Any, ...])
Expand All @@ -58,7 +58,7 @@ assert_type(b_i8_f8_f8.iters, tuple[np.flatiter[Any], ...])
assert_type(b_i8_f8_f8.nd, int)
assert_type(b_i8_f8_f8.ndim, int)
assert_type(b_i8_f8_f8.numiter, int)
assert_type(b_i8_f8_f8.shape, tuple[int, ...])
assert_type(b_i8_f8_f8.shape, tuple[Any, ...])
assert_type(b_i8_f8_f8.size, int)

assert_type(np.inner(AR_f8, AR_i8), Any)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.