Skip to content

Commit 0512a61

Browse files
committed
✨ use gradual shape-types by default
1 parent 6276844 commit 0512a61

File tree

14 files changed

+96
-88
lines changed

14 files changed

+96
-88
lines changed

src/_numtype/@test/test_to_array.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ bool_0d_reject_sc: _nt.ToBool_0d = f_0d # type: ignore[assignment] # pyright:
5959
bool_0d_reject_1d: _nt.ToBool_0d = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
6060
bool_0d_reject_2d: _nt.ToBool_0d = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
6161
bool_0d_reject_3d: _nt.ToBool_0d = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
62-
bool_0d_reject_nd: _nt.ToBool_0d = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
62+
bool_0d_reject_nd: _nt.ToBool_0d = b1_nd
6363

6464
bool_1d_accept: _nt.ToBool_1d = like_bool_1d
6565
bool_1d_reject_sc: _nt.ToBool_1d = f_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
6666
bool_1d_reject_0d: _nt.ToBool_1d = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
6767
bool_1d_reject_2d: _nt.ToBool_1ds = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
6868
bool_1d_reject_3d: _nt.ToBool_1ds = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
69-
bool_1d_reject_nd: _nt.ToBool_1ds = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
69+
bool_1d_reject_nd: _nt.ToBool_1ds = b1_nd
7070

7171
bool_2d_accept: _nt.ToBool_2d = like_bool_2d
7272
bool_2d_reject_sc: _nt.ToBool_2d = f_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
7373
bool_2d_reject_0d: _nt.ToBool_2d = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
7474
bool_2d_reject_1d: _nt.ToBool_2ds = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
7575
bool_2d_reject_3d: _nt.ToBool_2ds = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
76-
bool_2d_reject_nd: _nt.ToBool_2ds = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
76+
bool_2d_reject_nd: _nt.ToBool_2ds = b1_nd
7777

7878
bool_3d_accept: _nt.ToBool_3d = like_bool_3d
7979
bool_3d_reject_sc: _nt.ToBool_3d = f_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
8080
bool_3d_reject_0d: _nt.ToBool_3d = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
8181
bool_3d_reject_1d: _nt.ToBool_3ds = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
8282
bool_3d_reject_2d: _nt.ToBool_3ds = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
83-
bool_3d_reject_nd: _nt.ToBool_3ds = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
83+
bool_3d_reject_nd: _nt.ToBool_3ds = b1_nd
8484

8585
bool_nd_accept_0d: _nt.ToBool_nd = b1_0d
8686
bool_nd_accept_1d: _nt.ToBool_nd = like_bool_1d

src/_numtype/__init__.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ from ._scalar_co import (
141141
)
142142
from ._shape import (
143143
AnyShape as AnyShape,
144+
NeitherShape as NeitherShape,
144145
Shape as Shape,
145146
Shape0 as Shape0,
146147
Shape0N as Shape0N,
@@ -188,13 +189,17 @@ class CanArray3D(Protocol[_ScalarT_co]):
188189
@type_check_only
189190
class CanArrayND(Protocol[_ScalarT_co]):
190191
# TODO: remove `| Rank0` once python/mypy#19110 is fixed
191-
def __array__(self, /) -> np.ndarray[Shape | Rank0, np.dtype[_ScalarT_co]]: ...
192+
def __array__(self, /) -> np.ndarray[AnyShape | Rank0, np.dtype[_ScalarT_co]]: ...
192193

193194
@type_check_only
194195
class CanLenArrayND(Protocol[_ScalarT_co]):
195196
def __len__(self, /) -> int: ...
196197
# TODO: remove `| Rank0` once python/mypy#19110 is fixed
197-
def __array__(self, /) -> np.ndarray[Shape, np.dtype[_ScalarT_co]]: ...
198+
def __array__(self, /) -> np.ndarray[AnyShape, np.dtype[_ScalarT_co]]: ...
199+
200+
@type_check_only
201+
class CanArray(Protocol[_ScalarT_co, _ShapeT_co]):
202+
def __array__(self, /) -> np.ndarray[_ShapeT_co, np.dtype[_ScalarT_co]]: ...
198203

199204
@type_check_only
200205
class CanLenArray(Protocol[_ScalarT_co, _ShapeT_co]):
@@ -260,6 +265,7 @@ _ToArray_2nd: TypeAlias = CanLenArray[_ScalarT, Shape2N] | Sequence[_ToArray_1nd
260265
_ToArray2_2nd: TypeAlias = CanLenArray[_ScalarT, Shape2N] | Sequence[_ToArray2_1nd[_ScalarT, _ToT]]
261266
_ToArray_3nd: TypeAlias = CanLenArray[_ScalarT, Shape3N] | Sequence[_ToArray_2nd[_ScalarT]]
262267
_ToArray2_3nd: TypeAlias = CanLenArray[_ScalarT, Shape3N] | Sequence[_ToArray2_2nd[_ScalarT, _ToT]]
268+
_ToArray_nnd: TypeAlias = CanArray[_ScalarT, NeitherShape] # noqa: PYI047
263269

264270
###
265271
# Non-overlapping scalar- and array-like aliases for all scalar types.

src/_numtype/_array.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ __all__ = [
3232
###
3333

3434
# TODO: use `AnyShape` instead of `Shape` once python/mypy#19110 is fixed
35-
_RankT = TypeVar("_RankT", bound=AnyShape, default=Shape)
35+
_RankT = TypeVar("_RankT", bound=AnyShape, default=AnyShape)
3636
_ScalarT = TypeVar("_ScalarT", bound=np.generic, default=Any)
3737
_NaT = TypeVar("_NaT", default=Never)
3838

src/_numtype/_nep50.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import numpy as np
99
from numpy._typing import _NestedSequence
1010

1111
from . import _shape
12+
from ._rank import Rank0
1213

1314
__all__ = [
1415
"Casts",
@@ -122,7 +123,7 @@ class _LikeArray(Protocol[_LikeT_co, _ShapeT_co]):
122123
@type_check_only
123124
class _LikeScalar(Protocol[_LikeT_co]):
124125
@property
125-
def shape(self, /) -> _shape.Shape0: ...
126+
def __inner_shape__(self, /) -> Rank0: ...
126127
@property
127128
def dtype(self, /) -> _HasType[_LikeT_co]: ...
128129

src/_numtype/_shape.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from typing import Any, TypeAlias
1+
from typing import Any, Never, TypeAlias
22
from typing_extensions import TypeAliasType
33

44
__all__ = [
55
"AnyShape",
6+
"NeitherShape",
67
"Shape",
78
"Shape0",
89
"Shape0N",
@@ -17,8 +18,9 @@ __all__ = [
1718
"ShapeN",
1819
]
1920

20-
AnyShape = TypeAliasType("AnyShape", tuple[Any, ...])
2121
Shape = TypeAliasType("Shape", tuple[int, ...])
22+
AnyShape = TypeAliasType("AnyShape", tuple[Any, ...])
23+
NeitherShape = TypeAliasType("NeitherShape", tuple[Never, ...])
2224

2325
# TODO: remove `| Rank0` once python/mypy#19110 is fixed
2426
Shape0 = TypeAliasType("Shape0", tuple[()])

src/numpy-stubs/@test/static/accept/arrayterator.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _numtype as _nt
55
import numpy as np
66

77
AR_i8: _nt.Array[np.int64]
8-
ar_iter: np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]]
8+
ar_iter: np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]
99

1010
###
1111

@@ -14,16 +14,16 @@ assert_type(ar_iter.buf_size, int | None)
1414
assert_type(ar_iter.start, list[int])
1515
assert_type(ar_iter.stop, list[int])
1616
assert_type(ar_iter.step, list[int])
17-
assert_type(ar_iter.shape, tuple[int, ...])
18-
assert_type(ar_iter.flat, Generator[np.int64, None, None])
17+
assert_type(ar_iter.shape, _nt.AnyShape)
18+
assert_type(ar_iter.flat, Generator[np.int64])
1919

2020
assert_type(ar_iter.__array__(), _nt.Array[np.int64])
2121

2222
for i in ar_iter:
2323
assert_type(i, _nt.Array[np.int64])
2424

25-
assert_type(ar_iter[0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
26-
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
27-
assert_type(ar_iter[:], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
28-
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
29-
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
25+
assert_type(ar_iter[0], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]])
26+
assert_type(ar_iter[...], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]])
27+
assert_type(ar_iter[:], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]])
28+
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]])
29+
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]])

src/numpy-stubs/@test/static/accept/char.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import numpy as np
55

66
BytesArray: TypeAlias = _nt.Array[np.bytes_]
77
StrArray: TypeAlias = _nt.Array[np.str_]
8-
StringArray: TypeAlias = np.ndarray[_nt.Shape, np.dtypes.StringDType]
8+
StringArray: TypeAlias = np.ndarray[_nt.AnyShape, np.dtypes.StringDType]
99

1010
AR_S: BytesArray
1111
AR_U: StrArray
@@ -186,16 +186,16 @@ assert_type(np.char.istitle(AR_SUT), _nt.Array[np.bool])
186186
assert_type(np.char.isupper(AR_SUT), _nt.Array[np.bool])
187187
assert_type(np.char.str_len(AR_SUT), _nt.Array[np.int_])
188188

189-
assert_type(np.char.array(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
190-
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
191-
assert_type(np.char.array("bob", copy=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
192-
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
193-
assert_type(np.char.array(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
194-
assert_type(np.char.array(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
195-
196-
assert_type(np.char.asarray(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
197-
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
198-
assert_type(np.char.asarray("bob"), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
199-
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
200-
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])
201-
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
189+
assert_type(np.char.array(AR_U), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])
190+
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
191+
assert_type(np.char.array("bob", copy=True), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])
192+
assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
193+
assert_type(np.char.array(1, unicode=False), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
194+
assert_type(np.char.array(1, unicode=True), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])
195+
196+
assert_type(np.char.asarray(AR_U), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])
197+
assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
198+
assert_type(np.char.asarray("bob"), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])
199+
assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
200+
assert_type(np.char.asarray(1, unicode=False), np.char.chararray[_nt.AnyShape, np.dtype[np.bytes_]])
201+
assert_type(np.char.asarray(1, unicode=True), np.char.chararray[_nt.AnyShape, np.dtype[np.str_]])

src/numpy-stubs/@test/static/accept/chararray.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing_extensions import TypeVar
44
import _numtype as _nt
55
import numpy as np
66

7-
_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape, default=_nt.Shape)
7+
_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape, default=_nt.AnyShape)
88

99
_BytesArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.bytes_]]
1010
_StrArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.str_]]

src/numpy-stubs/@test/static/accept/ndarray_misc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import numpy as np
99

1010
###
1111

12-
class SubArray(np.ndarray[_nt.Shape, np.dtype[np.object_]]): ...
12+
class SubArray(np.ndarray[_nt.AnyShape, np.dtype[np.object_]]): ...
1313

1414
f8: np.float64
1515
i8: np.int64
@@ -151,7 +151,7 @@ assert_type(AR_f8.var(out=AR_O_sub), SubArray)
151151

152152
assert_type(AR_f8.argpartition([0]), _nt.Array[np.intp])
153153

154-
assert_type(AR_f8.diagonal(), _nt.Array[np.float64, Any])
154+
assert_type(AR_f8.diagonal(), _nt.Array[np.float64])
155155

156156
assert_type(AR_f8.dot(1), _nt.Array[Any])
157157
assert_type(AR_f8.dot([1]), Any)

src/numpy-stubs/__init__.pyi

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,11 +1776,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
17761776
@overload
17771777
def __getitem__(
17781778
self, key: _ArrayInteger_co | tuple[_ArrayInteger_co, ...], /
1779-
) -> ndarray[_nt.Shape, _DTypeT_co]: ...
1779+
) -> ndarray[_nt.AnyShape, _DTypeT_co]: ...
17801780
@overload
17811781
def __getitem__(self, key: CanIndex | tuple[CanIndex, ...], /) -> Any: ...
17821782
@overload
1783-
def __getitem__(self, key: _ToIndices, /) -> ndarray[_nt.Shape, _DTypeT_co]: ...
1783+
def __getitem__(self, key: _ToIndices, /) -> ndarray[_nt.AnyShape, _DTypeT_co]: ...
17841784
@overload
17851785
def __getitem__(self: _nt.Array[void], key: str, /) -> ndarray[_ShapeT_co]: ...
17861786
@overload
@@ -2452,55 +2452,47 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24522452

24532453
#
24542454
@overload
2455-
def __divmod__(self: _nt.Array[bool_, _nt.Shape], x: _nt.ToBool_nd, /) -> _Tuple2[_nt.Array[int8]]: ...
2455+
def __divmod__(self: _nt.Array[bool_], x: _nt.ToBool_nd, /) -> _Tuple2[_nt.Array[int8]]: ...
24562456
@overload
24572457
def __divmod__(
2458-
self: _nt.Array[_RealNumberT, _nt.Shape], x: _nt.Casts[_RealNumberT, _nt.Shape] | _nt.ToBool_nd, /
2458+
self: _nt.Array[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, /
24592459
) -> _Tuple2[_nt.Array[_RealNumberT]]: ...
24602460
@overload
24612461
def __divmod__(
2462-
self: _nt.Array[_CoFloatingT, _nt.Shape], x: _nt.CastsWith[_CoFloatingT, _RealScalarT, _nt.Shape], /
2462+
self: _nt.Array[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
24632463
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24642464
@overload
2465-
def __divmod__(
2466-
self: _nt.CastsWithInt[_RealScalarT, _nt.Shape], x: _PyIntND, /
2467-
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
2465+
def __divmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24682466
@overload
2469-
def __divmod__(
2470-
self: _nt.CastsWithFloat[_RealScalarT, _nt.Shape], x: _PyFloatND, /
2471-
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
2467+
def __divmod__(self: _nt.CastsWithFloat[_RealScalarT], x: _PyFloatND, /) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24722468
@overload
24732469
def __divmod__(
2474-
self: _nt.Array[timedelta64, _nt.Shape], x: _nt.ToTimeDelta_nd, /
2470+
self: _nt.Array[timedelta64], x: _nt.ToTimeDelta_nd, /
24752471
) -> tuple[_nt.Array[int64], _nt.Array[timedelta64]]: ...
24762472
@overload
2477-
def __divmod__(self: _nt.Array[object_, _nt.Shape], x: object, /) -> _Tuple2[_nt.Array[object_]]: ...
2473+
def __divmod__(self: _nt.Array[object_], x: object, /) -> _Tuple2[_nt.Array[object_]]: ...
24782474

24792475
#
24802476
@overload
2481-
def __rdivmod__(self: _nt.Array[bool_, _nt.Shape], x: _nt.ToBool_nd, /) -> _Tuple2[_nt.Array[int8]]: ...
2477+
def __rdivmod__(self: _nt.Array[bool_], x: _nt.ToBool_nd, /) -> _Tuple2[_nt.Array[int8]]: ...
24822478
@overload
24832479
def __rdivmod__(
2484-
self: _nt.Array[_RealNumberT, _nt.Shape], x: _nt.Casts[_RealNumberT, _nt.Shape] | _nt.ToBool_nd, /
2480+
self: _nt.Array[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, /
24852481
) -> _Tuple2[_nt.Array[_RealNumberT]]: ...
24862482
@overload
24872483
def __rdivmod__(
2488-
self: _nt.Array[_CoFloatingT, _nt.Shape], x: _nt.CastsWith[_CoFloatingT, _RealScalarT, _nt.Shape], /
2484+
self: _nt.Array[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
24892485
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24902486
@overload
2491-
def __rdivmod__(
2492-
self: _nt.CastsWithInt[_RealScalarT, _nt.Shape], x: _PyIntND, /
2493-
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
2487+
def __rdivmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24942488
@overload
2495-
def __rdivmod__(
2496-
self: _nt.CastsWithFloat[_RealScalarT, _nt.Shape], x: _PyFloatND, /
2497-
) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
2489+
def __rdivmod__(self: _nt.CastsWithFloat[_RealScalarT], x: _PyFloatND, /) -> _Tuple2[_nt.Array[_RealScalarT]]: ...
24982490
@overload
24992491
def __rdivmod__(
2500-
self: _nt.Array[timedelta64, _nt.Shape], x: _nt.ToTimeDelta_nd, /
2492+
self: _nt.Array[timedelta64], x: _nt.ToTimeDelta_nd, /
25012493
) -> tuple[_nt.Array[int64], _nt.Array[timedelta64]]: ...
25022494
@overload
2503-
def __rdivmod__(self: _nt.Array[object_, _nt.Shape], x: object, /) -> _Tuple2[_nt.Array[object_]]: ...
2495+
def __rdivmod__(self: _nt.Array[object_], x: object, /) -> _Tuple2[_nt.Array[object_]]: ...
25042496

25052497
#
25062498
@overload
@@ -2701,8 +2693,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27012693
def item(self: _HasDTypeWithItem[_T], /, *args: CanIndex) -> _T: ...
27022694

27032695
#
2704-
@overload # TODO(jorenham): remove `| Rank0` once python/mypy#19110 is fixed
2705-
def tolist(self: _HasShapeAndItem[_nt.Shape0 | _nt.Rank0, _T], /) -> _T: ... # type: ignore[overload-overlap]
2696+
@overload # workaround for python/mypy#19110
2697+
def tolist(self: _HasShapeAndItem[_nt.Rank0, _T], /) -> _T: ... # type: ignore[overload-overlap]
2698+
@overload # workaround for microsoft/pyright#10232
2699+
def tolist(self: ndarray[_nt.NeitherShape], /) -> Any: ...
2700+
@overload
2701+
def tolist(self: _HasShapeAndItem[_nt.Shape0, _T], /) -> _T: ...
27062702
@overload
27072703
def tolist(self: _HasShapeAndItem[_nt.Shape1, _T], /) -> list[_T]: ...
27082704
@overload
@@ -2741,7 +2737,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27412737

27422738
#
27432739
def swapaxes(self, /, axis1: CanIndex, axis2: CanIndex) -> Self: ...
2744-
def squeeze(self, /, axis: CanIndex | tuple[CanIndex, ...] | None = None) -> ndarray[_nt.Shape, _DTypeT_co]: ...
2740+
def squeeze(self, /, axis: CanIndex | tuple[CanIndex, ...] | None = None) -> ndarray[_nt.AnyShape, _DTypeT_co]: ...
27452741
def byteswap(self, /, inplace: py_bool = False) -> Self: ...
27462742

27472743
#
@@ -2751,6 +2747,10 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27512747
def transpose(self, /, *axes: CanIndex) -> Self: ...
27522748

27532749
# NOTE: always raises when called on `generic`.
2750+
@overload # this overload is a workaround for microsoft/pyright#10232
2751+
def diagonal( # type: ignore[overload-overlap]
2752+
self: ndarray[_nt.NeitherShape, _DTypeT], /, offset: CanIndex = 0, axis1: CanIndex = 0, axis2: CanIndex = 1
2753+
) -> ndarray[_nt.AnyShape, _DTypeT]: ...
27542754
@overload
27552755
def diagonal(
27562756
self: ndarray[_nt.Shape2, _DTypeT], /, offset: CanIndex = 0, axis1: CanIndex = 0, axis2: CanIndex = 1
@@ -2770,7 +2770,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27702770
@overload
27712771
def diagonal(
27722772
self, /, offset: CanIndex = 0, axis1: CanIndex = 0, axis2: CanIndex = 1
2773-
) -> ndarray[Any, _DTypeT_co]: ...
2773+
) -> ndarray[_nt.AnyShape, _DTypeT_co]: ...
27742774

27752775
#
27762776
@overload
@@ -2995,7 +2995,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
29952995
@overload
29962996
def take(
29972997
self, /, indices: _nt.CoInteger_nd, axis: CanIndex | None = None, out: None = None, mode: _ModeKind = "raise"
2998-
) -> ndarray[_nt.Shape, _DTypeT_co]: ...
2998+
) -> ndarray[_nt.AnyShape, _DTypeT_co]: ...
29992999
@overload
30003000
def take(
30013001
self, /, indices: _nt.CoInteger_nd, axis: CanIndex | None, out: _ArrayT, mode: _ModeKind = "raise"

0 commit comments

Comments
 (0)