Skip to content

Commit 43efc06

Browse files
committed
replace numpy._typing._ArrayLike* co-aliases with _numtype equivalents
1 parent 8fd2b40 commit 43efc06

15 files changed

Lines changed: 121 additions & 141 deletions

File tree

src/numpy-stubs/@test/static/reject/comparisons.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AR_c > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
2525

2626
AR_m > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
2727
AR_m > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
28-
AR_m > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
28+
AR_m > AR_M # type: ignore[operator]
2929
AR_m > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3030
AR_m > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3131

@@ -34,6 +34,6 @@ AR_m > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3434
AR_M > AR_i # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3535
AR_M > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3636
AR_M > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
37-
AR_M > AR_m # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
37+
AR_M > AR_m # type: ignore[operator]
3838
AR_M > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3939
AR_M > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

src/numpy-stubs/@test/static/reject/rec.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ np.rec.fromarrays( # type: ignore[call-overload] # pyright: ignore[reportCallI
1010
formats=["f8", "f8"], # pyright: ignore[reportArgumentType]
1111
)
1212

13-
np.rec.fromrecords(AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
13+
np.rec.fromrecords(AR_i8) # type: ignore[arg-type]
1414
np.rec.fromrecords( # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
1515
[(1.5,)],
1616
dtype=[("f8", "f8")],

src/numpy-stubs/__init__.pyi

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ from ._pytesttester import PytestTester
338338
from ._typing import (
339339
ArrayLike,
340340
DTypeLike,
341-
_ArrayLikeDT64_co,
342-
_ArrayLikeObject_co,
343-
_ArrayLikeTD64_co,
344341
_DTypeLike,
345342
_NestedSequence,
346343
_NumberLike_co,
@@ -1867,49 +1864,49 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
18671864
@overload
18681865
def __lt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18691866
@overload
1870-
def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1867+
def __lt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18711868
@overload
1872-
def __lt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1869+
def __lt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18731870
@overload
18741871
def __lt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
18751872
@overload
1876-
def __lt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1873+
def __lt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
18771874

18781875
#
18791876
@overload
18801877
def __le__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18811878
@overload
1882-
def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1879+
def __le__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18831880
@overload
1884-
def __le__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1881+
def __le__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18851882
@overload
18861883
def __le__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
18871884
@overload
1888-
def __le__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1885+
def __le__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
18891886

18901887
#
18911888
@overload
18921889
def __gt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18931890
@overload
1894-
def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1891+
def __gt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18951892
@overload
1896-
def __gt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1893+
def __gt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18971894
@overload
18981895
def __gt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
18991896
@overload
1900-
def __gt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1897+
def __gt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
19011898

19021899
#
19031900
@overload
19041901
def __ge__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
19051902
@overload
1906-
def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1903+
def __ge__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
19071904
@overload
1908-
def __ge__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1905+
def __ge__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
19091906
@overload
19101907
def __ge__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
19111908
@overload
1912-
def __ge__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1909+
def __ge__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
19131910

19141911
#
19151912
def __abs__(
@@ -5045,7 +5042,7 @@ class void(flexible[bytes | tuple[Any, ...]]): # type: ignore[misc] # pyright:
50455042
def dtype(self) -> dtypes.VoidDType: ...
50465043

50475044
class datetime64(
5048-
_RealMixin, _CmpOpMixin[datetime64, _ArrayLikeDT64_co], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
5045+
_RealMixin, _CmpOpMixin[datetime64, _nt.CoDateTime_nd], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
50495046
):
50505047
@classmethod
50515048
def __class_getitem__(cls, type_arg: type | object, /) -> GenericAlias: ...

src/numpy-stubs/_core/_multiarray_umath.pyi

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ from numpy import _AnyShapeT, _CanSeekTellFileNo, _CastingKind, _ModeKind, _Orde
2929
from numpy._globals import _CopyMode
3030
from numpy._typing import (
3131
_ArrayLike,
32-
_ArrayLikeAnyString_co,
33-
_ArrayLikeNumber_co,
3432
_DTypeLike,
3533
_ScalarLike_co,
3634
_SupportsArrayFunc as _CanArrayFunc,
@@ -1673,13 +1671,13 @@ def dot(a: npt.ArrayLike, b: npt.ArrayLike, out: _ArrayT) -> _ArrayT: ...
16731671

16741672
#
16751673
@overload
1676-
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
1674+
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap]
16771675
@overload
16781676
def vdot(a: _nt.CoInteger_nd, b: _nt.CoInteger_nd, /) -> np.signedinteger: ...
16791677
@overload
16801678
def vdot(a: _nt.CoFloating_nd, b: _nt.CoFloating_nd, /) -> np.floating | np.signedinteger: ...
16811679
@overload
1682-
def vdot(a: _ArrayLikeNumber_co, b: _ArrayLikeNumber_co, /) -> np.inexact | np.signedinteger: ...
1680+
def vdot(a: _nt.CoComplex_nd, b: _nt.CoComplex_nd, /) -> np.inexact | np.signedinteger: ...
16831681

16841682
#
16851683
@overload
@@ -1728,31 +1726,31 @@ def interp(
17281726
def interp_complex(
17291727
x: _ToFloat,
17301728
xp: _nt.CoFloating_nd,
1731-
fp: _ArrayLikeNumber_co,
1729+
fp: _nt.CoComplex_nd,
17321730
left: _ToComplex | None = None,
17331731
right: _ToComplex | None = None,
17341732
) -> np.complex128: ...
17351733
@overload
17361734
def interp_complex(
17371735
x: _nt.Array[np.floating | np.integer, _ShapeT],
17381736
xp: _nt.CoFloating_nd,
1739-
fp: _ArrayLikeNumber_co,
1737+
fp: _nt.CoComplex_nd,
17401738
left: _ToComplex | None = None,
17411739
right: _ToComplex | None = None,
17421740
) -> _nt.Array[np.complex128, _ShapeT]: ...
17431741
@overload
17441742
def interp_complex(
17451743
x: _nt.Sequence1ND[_ToFloat],
17461744
xp: _nt.CoFloating_nd,
1747-
fp: _ArrayLikeNumber_co,
1745+
fp: _nt.CoComplex_nd,
17481746
left: _ToComplex | None = None,
17491747
right: _ToComplex | None = None,
17501748
) -> _nt.Array[np.complex128]: ...
17511749
@overload
17521750
def interp_complex(
17531751
x: _nt.CoFloating_nd,
17541752
xp: _nt.CoFloating_nd,
1755-
fp: _ArrayLikeNumber_co,
1753+
fp: _nt.CoComplex_nd,
17561754
left: _ToComplex | None = None,
17571755
right: _ToComplex | None = None,
17581756
) -> np.complex128 | _nt.Array[np.complex128]: ...
@@ -2021,4 +2019,4 @@ def _make_extobj() -> CapsuleType: ...
20212019
def _monotonicity(x: _nt.CoFloating_nd) -> L[0, 1]: ...
20222020
def _place(input: npt.ArrayLike, mask: _nt.ToBool_nd, vals: npt.ArrayLike) -> None: ...
20232021
def _reconstruct(subtype: type[_nt.Array], shape: _AnyShapeT, dtype: _DTypeT) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
2024-
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...
2022+
def _vec_string(a: _nt.ToCharacter_nd, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...

src/numpy-stubs/_core/einsumfunc.pyi

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ from typing_extensions import TypeVar
66
import _numtype as _nt
77
from numpy import _OrderKACF # noqa: ICN003
88
from numpy._typing import (
9-
_ArrayLikeBool_co,
10-
_ArrayLikeComplex_co,
11-
_ArrayLikeFloat_co,
12-
_ArrayLikeInt_co,
13-
_ArrayLikeObject_co,
14-
_ArrayLikeUInt_co,
9+
_DTypeLikeBool,
10+
_DTypeLikeComplex,
11+
_DTypeLikeComplex_co,
12+
_DTypeLikeFloat,
13+
_DTypeLikeInt,
14+
_DTypeLikeObject,
15+
_DTypeLikeUInt,
1516
)
1617

1718
__all__ = ["einsum", "einsum_path"]
@@ -39,9 +40,9 @@ _ToDTypeComplex_co: TypeAlias = _nt.ToDTypeBool | _ToDTypeUInt | _ToDTypeInt | _
3940
# Something like `is_scalar = bool(__subscripts.partition("->")[-1])`
4041
@overload
4142
def einsum(
42-
subscripts: str | _ArrayLikeInt_co,
43+
subscripts: str | _nt.CoInteger_nd,
4344
/,
44-
*operands: _ArrayLikeBool_co,
45+
*operands: _nt.ToBool_nd,
4546
out: None = None,
4647
optimize: _OptimizeKind = False,
4748
dtype: _nt.ToDTypeBool | None = None,
@@ -50,9 +51,9 @@ def einsum(
5051
) -> Incomplete: ...
5152
@overload
5253
def einsum(
53-
subscripts: str | _ArrayLikeInt_co,
54+
subscripts: str | _nt.CoInteger_nd,
5455
/,
55-
*operands: _ArrayLikeUInt_co,
56+
*operands: _nt.CoUInt64_nd,
5657
out: None = None,
5758
dtype: _ToDTypeUInt | None = None,
5859
order: _OrderKACF = "K",
@@ -61,9 +62,9 @@ def einsum(
6162
) -> Incomplete: ...
6263
@overload
6364
def einsum(
64-
subscripts: str | _ArrayLikeInt_co,
65+
subscripts: str | _nt.CoInteger_nd,
6566
/,
66-
*operands: _ArrayLikeInt_co,
67+
*operands: _nt.CoInteger_nd,
6768
out: None = None,
6869
dtype: _ToDTypeInt | None = None,
6970
order: _OrderKACF = "K",
@@ -72,9 +73,9 @@ def einsum(
7273
) -> Incomplete: ...
7374
@overload
7475
def einsum(
75-
subscripts: str | _ArrayLikeInt_co,
76+
subscripts: str | _nt.CoInteger_nd,
7677
/,
77-
*operands: _ArrayLikeFloat_co,
78+
*operands: _nt.CoFloating_nd,
7879
out: None = None,
7980
dtype: _ToDTypeFloat | None = None,
8081
order: _OrderKACF = "K",
@@ -83,9 +84,9 @@ def einsum(
8384
) -> Incomplete: ...
8485
@overload
8586
def einsum(
86-
subscripts: str | _ArrayLikeInt_co,
87+
subscripts: str | _nt.CoInteger_nd,
8788
/,
88-
*operands: _ArrayLikeComplex_co,
89+
*operands: _nt.CoComplex_nd,
8990
out: None = None,
9091
dtype: _ToDTypeComplex | None = None,
9192
order: _OrderKACF = "K",
@@ -94,7 +95,7 @@ def einsum(
9495
) -> Incomplete: ...
9596
@overload
9697
def einsum(
97-
subscripts: str | _ArrayLikeInt_co,
98+
subscripts: str | _nt.CoInteger_nd,
9899
/,
99100
*operands: Any,
100101
casting: _CastingUnsafe,
@@ -105,9 +106,9 @@ def einsum(
105106
) -> Incomplete: ...
106107
@overload
107108
def einsum(
108-
subscripts: str | _ArrayLikeInt_co,
109+
subscripts: str | _nt.CoInteger_nd,
109110
/,
110-
*operands: _ArrayLikeComplex_co,
111+
*operands: _nt.CoComplex_nd,
111112
out: _ArrayT,
112113
dtype: _ToDTypeComplex_co | None = None,
113114
order: _OrderKACF = "K",
@@ -116,7 +117,7 @@ def einsum(
116117
) -> _ArrayT: ...
117118
@overload
118119
def einsum(
119-
subscripts: str | _ArrayLikeInt_co,
120+
subscripts: str | _nt.CoInteger_nd,
120121
/,
121122
*operands: Any,
122123
out: _ArrayT,
@@ -127,9 +128,9 @@ def einsum(
127128
) -> _ArrayT: ...
128129
@overload
129130
def einsum(
130-
subscripts: str | _ArrayLikeInt_co,
131+
subscripts: str | _nt.CoInteger_nd,
131132
/,
132-
*operands: _ArrayLikeObject_co,
133+
*operands: _nt.ToObject_nd,
133134
out: None = None,
134135
dtype: _nt.ToDTypeObject | None = None,
135136
order: _OrderKACF = "K",
@@ -138,7 +139,7 @@ def einsum(
138139
) -> Incomplete: ...
139140
@overload
140141
def einsum(
141-
subscripts: str | _ArrayLikeInt_co,
142+
subscripts: str | _nt.CoInteger_nd,
142143
/,
143144
*operands: Any,
144145
casting: _CastingUnsafe,
@@ -149,9 +150,9 @@ def einsum(
149150
) -> Incomplete: ...
150151
@overload
151152
def einsum(
152-
subscripts: str | _ArrayLikeInt_co,
153+
subscripts: str | _nt.CoInteger_nd,
153154
/,
154-
*operands: _ArrayLikeObject_co,
155+
*operands: _nt.ToObject_nd,
155156
out: _ArrayT,
156157
dtype: _nt.ToDTypeObject | None = None,
157158
order: _OrderKACF = "K",
@@ -160,7 +161,7 @@ def einsum(
160161
) -> _ArrayT: ...
161162
@overload
162163
def einsum(
163-
subscripts: str | _ArrayLikeInt_co,
164+
subscripts: str | _nt.CoInteger_nd,
164165
/,
165166
*operands: Any,
166167
out: _ArrayT,
@@ -174,9 +175,9 @@ def einsum(
174175
# NOTE: `einsum_call` is a hidden kwarg unavailable for public use.
175176
# It is therefore excluded from the signatures below.
176177
def einsum_path(
177-
subscripts: str | _ArrayLikeInt_co,
178+
subscripts: str | _nt.CoInteger_nd,
178179
/,
179-
*operands: _ArrayLikeComplex_co | _nt.ToDTypeObject,
180+
*operands: _nt.CoComplex_nd | _nt.ToDTypeObject,
180181
optimize: _OptimizeKind = "greedy",
181182
einsum_call: L[False] = False,
182183
) -> tuple[list[str | tuple[int, ...]], str]: ...

src/numpy-stubs/_core/records.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from typing_extensions import Buffer, TypeVar, override
66
import _numtype as _nt
77
import numpy as np
88
from numpy import _ByteOrder, _OrderKACF # noqa: ICN003
9-
from numpy._typing import ArrayLike, DTypeLike, _ArrayLikeVoid_co
9+
from numpy._typing import ArrayLike, DTypeLike, _ShapeLike
1010

1111
__all__ = [
1212
"array",
@@ -145,7 +145,7 @@ def fromarrays(
145145
# exported in `numpy.rec`
146146
@overload
147147
def fromrecords(
148-
recList: _ArrayLikeVoid_co | _nt.SequenceND[tuple[Incomplete, ...]],
148+
recList: _nt.ToGeneric_nd | _nt.SequenceND[tuple[Incomplete, ...]],
149149
dtype: DTypeLike | None = None,
150150
shape: _nt.ToShape | None = None,
151151
formats: None = None,
@@ -156,7 +156,7 @@ def fromrecords(
156156
) -> _RecArray[record]: ...
157157
@overload
158158
def fromrecords(
159-
recList: _ArrayLikeVoid_co | _nt.SequenceND[tuple[Incomplete, ...]],
159+
recList: _nt.ToGeneric_nd | _nt.SequenceND[tuple[Incomplete, ...]],
160160
dtype: None = None,
161161
shape: _nt.ToShape | None = None,
162162
*,

src/numpy-stubs/_core/strings.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from typing import TypeAlias, overload
33
import _numtype as _nt
44
import numpy as np
55
from numpy._globals import _NoValueType
6-
from numpy._typing import _ArrayLikeAnyString_co as ToAnyStringND, _ArrayLikeInt_co as ToIntND
76

87
from .umath import (
98
add,
@@ -25,6 +24,9 @@ from .umath import (
2524
str_len,
2625
)
2726

27+
ToAnyStringND = _nt.ToCharacter_nd
28+
ToIntND = _nt.CoInteger_nd
29+
2830
__all__ = [
2931
"add",
3032
"capitalize",

src/numpy-stubs/fft/_pocketfft.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ from typing import Literal as L, TypeAlias
44
import _numtype as _nt
55
import numpy as np
66
import numpy.typing as npt
7-
from numpy._typing import _ArrayLikeNumber_co
87

98
__all__ = [
109
"fft",
@@ -56,7 +55,7 @@ def irfft(
5655

5756
# Input array must be compatible with `np.conjugate`
5857
def hfft(
59-
a: _ArrayLikeNumber_co,
58+
a: _nt.CoComplex_nd,
6059
n: int | None = None,
6160
axis: int = -1,
6261
norm: _NormKind = None,

0 commit comments

Comments
 (0)