Repository: numpy/numpy
File: numpy/typing/tests/data/reveal/fromnumeric.pyi (Python)

Code before:
assert_type(np.resize(AR_b, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.bool]])
assert_type(np.resize(AR_f4, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.float32]])

assert_type(np.squeeze(b), np.bool)
assert_type(np.squeeze(f4), np.float32)
assert_type(np.squeeze(f), npt.NDArray[Any])
assert_type(np.squeeze(AR_b), npt.NDArray[np.bool])
assert_type(np.squeeze(AR_f4), npt.NDArray[np.float32])

assert_type(np.diagonal(AR_b), npt.NDArray[np.bool])
assert_type(np.diagonal(AR_f4), npt.NDArray[np.float32])

assert_type(np.trace(AR_b), Any)
assert_type(np.trace(AR_f4), Any)
assert_type(np.trace(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.ravel(b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.ravel(f), np.ndarray[tuple[int], np.dtype[np.float64 | np.int_ | np.bool]])
assert_type(np.ravel(AR_b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.nonzero(AR_b), tuple[_Array1D[np.intp], *tuple[_Array1D[np.intp], ...]])
assert_type(np.nonzero(AR_f4), tuple[_Array1D[np.intp], *tuple[_Array1D[np.intp], ...]])
assert_type(np.nonzero(AR_1d), tuple[_Array1D[np.intp], *tuple[_Array1D[np.intp], ...]])
assert_type(np.nonzero(AR_nd), tuple[_Array1D[np.intp], *tuple[_Array1D[np.intp], ...]])

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[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])
# assert_type(np.shape(AR_2d), tuple[int, int])

assert_type(np.compress([True], b), npt.NDArray[np.bool])
assert_type(np.compress([True], f4), npt.NDArray[np.float32])
assert_type(np.compress([True], f), npt.NDArray[Any])
assert_type(np.compress([True], AR_b), npt.NDArray[np.bool])
assert_type(np.compress([True], AR_f4), npt.NDArray[np.float32])

assert_type(np.clip(b, 0, 1.0), np.bool)
assert_type(np.clip(f4, -1, 1), np.float32)
assert_type(np.clip(f, 0, 1), Any)
assert_type(np.clip(AR_b, 0, 1), npt.NDArray[np.bool])
assert_type(np.clip(AR_f4, 0, 1), npt.NDArray[np.float32])
assert_type(np.clip([0], 0, 1), npt.NDArray[Any])

Review comment (refactor):
these are all the same, so something like

```
_Indices: TypeAlias = tuple[np.ndarray[tuple[int], np.dtype[np.intp]], ...]
```

could simplify things a bit.

Code after:
assert_type(np.squeeze(b), np.bool)
assert_type(np.squeeze(f4), np.float32)
assert_type(np.squeeze(f), npt.NDArray[Any])
assert_type(np.squeeze(AR_b), npt.NDArray[np.bool])
assert_type(np.squeeze(AR_f4), npt.NDArray[np.float32])

assert_type(np.diagonal(AR_b), npt.NDArray[np.bool])
assert_type(np.diagonal(AR_f4), npt.NDArray[np.float32])

assert_type(np.trace(AR_b), Any)
assert_type(np.trace(AR_f4), Any)
assert_type(np.trace(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.ravel(b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.ravel(f), np.ndarray[tuple[int], np.dtype[np.float64 | np.int_ | np.bool]])
assert_type(np.ravel(AR_b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.nonzero(AR_b), tuple[np.ndarray[tuple[int], np.dtype[np.intp]], ...])
assert_type(np.nonzero(AR_f4), tuple[np.ndarray[tuple[int], np.dtype[np.intp]], ...])
assert_type(np.nonzero(AR_1d), tuple[np.ndarray[tuple[int], np.dtype[np.intp]], ...])
assert_type(np.nonzero(AR_nd), tuple[np.ndarray[tuple[int], np.dtype[np.intp]], ...])

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[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])
# assert_type(np.shape(AR_2d), tuple[int, int])

assert_type(np.compress([True], b), npt.NDArray[np.bool])
assert_type(np.compress([True], f4), npt.NDArray[np.float32])
assert_type(np.compress([True], f), npt.NDArray[Any])
assert_type(np.compress([True], AR_b), npt.NDArray[np.bool])
assert_type(np.compress([True], AR_f4), npt.NDArray[np.float32])

assert_type(np.clip(b, 0, 1.0), np.bool)
assert_type(np.clip(f4, -1, 1), np.float32)
assert_type(np.clip(f, 0, 1), Any)
assert_type(np.clip(AR_b, 0, 1), npt.NDArray[np.bool])
assert_type(np.clip(AR_f4, 0, 1), npt.NDArray[np.float32])
assert_type(np.clip([0], 0, 1), npt.NDArray[Any])
assert_type(np.clip(AR_b, 0, 1, out=AR_subclass), NDArraySubclass)

assert_type(np.sum(b), np.bool)