Skip to content

Commit c389294

Browse files
committed
replace numpy._typing._ArrayLike* co-aliases with _numtype equivalents
1 parent 9f15ec1 commit c389294

15 files changed

Lines changed: 114 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
_DTypeLikeVoid,
346343
_NestedSequence,
@@ -1869,49 +1866,49 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
18691866
@overload
18701867
def __lt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18711868
@overload
1872-
def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1869+
def __lt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18731870
@overload
1874-
def __lt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1871+
def __lt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18751872
@overload
18761873
def __lt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
18771874
@overload
1878-
def __lt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1875+
def __lt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
18791876

18801877
#
18811878
@overload
18821879
def __le__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18831880
@overload
1884-
def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1881+
def __le__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18851882
@overload
1886-
def __le__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1883+
def __le__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18871884
@overload
18881885
def __le__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
18891886
@overload
1890-
def __le__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1887+
def __le__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
18911888

18921889
#
18931890
@overload
18941891
def __gt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
18951892
@overload
1896-
def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1893+
def __gt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
18971894
@overload
1898-
def __gt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1895+
def __gt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
18991896
@overload
19001897
def __gt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
19011898
@overload
1902-
def __gt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1899+
def __gt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
19031900

19041901
#
19051902
@overload
19061903
def __ge__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
19071904
@overload
1908-
def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
1905+
def __ge__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
19091906
@overload
1910-
def __ge__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
1907+
def __ge__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
19111908
@overload
19121909
def __ge__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
19131910
@overload
1914-
def __ge__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
1911+
def __ge__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...
19151912

19161913
#
19171914
def __abs__(
@@ -5047,7 +5044,7 @@ class void(flexible[bytes | tuple[Any, ...]]): # type: ignore[misc] # pyright:
50475044
def dtype(self) -> dtypes.VoidDType: ...
50485045

50495046
class datetime64(
5050-
_RealMixin, _CmpOpMixin[datetime64, _ArrayLikeDT64_co], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
5047+
_RealMixin, _CmpOpMixin[datetime64, _nt.CoDateTime_nd], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
50515048
):
50525049
@classmethod
50535050
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
_ShapeLike,
@@ -1674,13 +1672,13 @@ def dot(a: npt.ArrayLike, b: npt.ArrayLike, out: _ArrayT) -> _ArrayT: ...
16741672

16751673
#
16761674
@overload
1677-
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
1675+
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap]
16781676
@overload
16791677
def vdot(a: _nt.CoInteger_nd, b: _nt.CoInteger_nd, /) -> np.signedinteger: ...
16801678
@overload
16811679
def vdot(a: _nt.CoFloating_nd, b: _nt.CoFloating_nd, /) -> np.floating | np.signedinteger: ...
16821680
@overload
1683-
def vdot(a: _ArrayLikeNumber_co, b: _ArrayLikeNumber_co, /) -> np.inexact | np.signedinteger: ...
1681+
def vdot(a: _nt.CoComplex_nd, b: _nt.CoComplex_nd, /) -> np.inexact | np.signedinteger: ...
16841682

16851683
#
16861684
@overload
@@ -1729,31 +1727,31 @@ def interp(
17291727
def interp_complex(
17301728
x: _ToFloat,
17311729
xp: _nt.CoFloating_nd,
1732-
fp: _ArrayLikeNumber_co,
1730+
fp: _nt.CoComplex_nd,
17331731
left: _ToComplex | None = None,
17341732
right: _ToComplex | None = None,
17351733
) -> np.complex128: ...
17361734
@overload
17371735
def interp_complex(
17381736
x: _nt.Array[np.floating | np.integer, _ShapeT],
17391737
xp: _nt.CoFloating_nd,
1740-
fp: _ArrayLikeNumber_co,
1738+
fp: _nt.CoComplex_nd,
17411739
left: _ToComplex | None = None,
17421740
right: _ToComplex | None = None,
17431741
) -> _nt.Array[np.complex128, _ShapeT]: ...
17441742
@overload
17451743
def interp_complex(
17461744
x: _nt.Sequence1ND[_ToFloat],
17471745
xp: _nt.CoFloating_nd,
1748-
fp: _ArrayLikeNumber_co,
1746+
fp: _nt.CoComplex_nd,
17491747
left: _ToComplex | None = None,
17501748
right: _ToComplex | None = None,
17511749
) -> _nt.Array[np.complex128]: ...
17521750
@overload
17531751
def interp_complex(
17541752
x: _nt.CoFloating_nd,
17551753
xp: _nt.CoFloating_nd,
1756-
fp: _ArrayLikeNumber_co,
1754+
fp: _nt.CoComplex_nd,
17571755
left: _ToComplex | None = None,
17581756
right: _ToComplex | None = None,
17591757
) -> np.complex128 | _nt.Array[np.complex128]: ...
@@ -2022,4 +2020,4 @@ def _make_extobj() -> CapsuleType: ...
20222020
def _monotonicity(x: _nt.CoFloating_nd) -> L[0, 1]: ...
20232021
def _place(input: npt.ArrayLike, mask: _nt.ToBool_nd, vals: npt.ArrayLike) -> None: ...
20242022
def _reconstruct(subtype: type[_nt.Array], shape: _AnyShapeT, dtype: _DTypeT) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
2025-
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...
2023+
def _vec_string(a: _nt.ToCharacter_nd, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...

src/numpy-stubs/_core/einsumfunc.pyi

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ 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,
159
_DTypeLikeBool,
1610
_DTypeLikeComplex,
1711
_DTypeLikeComplex_co,
@@ -38,9 +32,9 @@ _CastingUnsafe: TypeAlias = Literal["unsafe"]
3832
# Something like `is_scalar = bool(__subscripts.partition("->")[-1])`
3933
@overload
4034
def einsum(
41-
subscripts: str | _ArrayLikeInt_co,
35+
subscripts: str | _nt.CoInteger_nd,
4236
/,
43-
*operands: _ArrayLikeBool_co,
37+
*operands: _nt.ToBool_nd,
4438
out: None = None,
4539
optimize: _OptimizeKind = False,
4640
dtype: _DTypeLikeBool | None = None,
@@ -49,9 +43,9 @@ def einsum(
4943
) -> Incomplete: ...
5044
@overload
5145
def einsum(
52-
subscripts: str | _ArrayLikeInt_co,
46+
subscripts: str | _nt.CoInteger_nd,
5347
/,
54-
*operands: _ArrayLikeUInt_co,
48+
*operands: _nt.CoUInt64_nd,
5549
out: None = None,
5650
dtype: _DTypeLikeUInt | None = None,
5751
order: _OrderKACF = "K",
@@ -60,9 +54,9 @@ def einsum(
6054
) -> Incomplete: ...
6155
@overload
6256
def einsum(
63-
subscripts: str | _ArrayLikeInt_co,
57+
subscripts: str | _nt.CoInteger_nd,
6458
/,
65-
*operands: _ArrayLikeInt_co,
59+
*operands: _nt.CoInteger_nd,
6660
out: None = None,
6761
dtype: _DTypeLikeInt | None = None,
6862
order: _OrderKACF = "K",
@@ -71,9 +65,9 @@ def einsum(
7165
) -> Incomplete: ...
7266
@overload
7367
def einsum(
74-
subscripts: str | _ArrayLikeInt_co,
68+
subscripts: str | _nt.CoInteger_nd,
7569
/,
76-
*operands: _ArrayLikeFloat_co,
70+
*operands: _nt.CoFloating_nd,
7771
out: None = None,
7872
dtype: _DTypeLikeFloat | None = None,
7973
order: _OrderKACF = "K",
@@ -82,9 +76,9 @@ def einsum(
8276
) -> Incomplete: ...
8377
@overload
8478
def einsum(
85-
subscripts: str | _ArrayLikeInt_co,
79+
subscripts: str | _nt.CoInteger_nd,
8680
/,
87-
*operands: _ArrayLikeComplex_co,
81+
*operands: _nt.CoComplex_nd,
8882
out: None = None,
8983
dtype: _DTypeLikeComplex | None = None,
9084
order: _OrderKACF = "K",
@@ -93,7 +87,7 @@ def einsum(
9387
) -> Incomplete: ...
9488
@overload
9589
def einsum(
96-
subscripts: str | _ArrayLikeInt_co,
90+
subscripts: str | _nt.CoInteger_nd,
9791
/,
9892
*operands: Any,
9993
casting: _CastingUnsafe,
@@ -104,9 +98,9 @@ def einsum(
10498
) -> Incomplete: ...
10599
@overload
106100
def einsum(
107-
subscripts: str | _ArrayLikeInt_co,
101+
subscripts: str | _nt.CoInteger_nd,
108102
/,
109-
*operands: _ArrayLikeComplex_co,
103+
*operands: _nt.CoComplex_nd,
110104
out: _ArrayT,
111105
dtype: _DTypeLikeComplex_co | None = None,
112106
order: _OrderKACF = "K",
@@ -115,7 +109,7 @@ def einsum(
115109
) -> _ArrayT: ...
116110
@overload
117111
def einsum(
118-
subscripts: str | _ArrayLikeInt_co,
112+
subscripts: str | _nt.CoInteger_nd,
119113
/,
120114
*operands: Any,
121115
out: _ArrayT,
@@ -126,9 +120,9 @@ def einsum(
126120
) -> _ArrayT: ...
127121
@overload
128122
def einsum(
129-
subscripts: str | _ArrayLikeInt_co,
123+
subscripts: str | _nt.CoInteger_nd,
130124
/,
131-
*operands: _ArrayLikeObject_co,
125+
*operands: _nt.ToObject_nd,
132126
out: None = None,
133127
dtype: _DTypeLikeObject | None = None,
134128
order: _OrderKACF = "K",
@@ -137,7 +131,7 @@ def einsum(
137131
) -> Incomplete: ...
138132
@overload
139133
def einsum(
140-
subscripts: str | _ArrayLikeInt_co,
134+
subscripts: str | _nt.CoInteger_nd,
141135
/,
142136
*operands: Any,
143137
casting: _CastingUnsafe,
@@ -148,9 +142,9 @@ def einsum(
148142
) -> Incomplete: ...
149143
@overload
150144
def einsum(
151-
subscripts: str | _ArrayLikeInt_co,
145+
subscripts: str | _nt.CoInteger_nd,
152146
/,
153-
*operands: _ArrayLikeObject_co,
147+
*operands: _nt.ToObject_nd,
154148
out: _ArrayT,
155149
dtype: _DTypeLikeObject | None = None,
156150
order: _OrderKACF = "K",
@@ -159,7 +153,7 @@ def einsum(
159153
) -> _ArrayT: ...
160154
@overload
161155
def einsum(
162-
subscripts: str | _ArrayLikeInt_co,
156+
subscripts: str | _nt.CoInteger_nd,
163157
/,
164158
*operands: Any,
165159
out: _ArrayT,
@@ -173,9 +167,9 @@ def einsum(
173167
# NOTE: `einsum_call` is a hidden kwarg unavailable for public use.
174168
# It is therefore excluded from the signatures below.
175169
def einsum_path(
176-
subscripts: str | _ArrayLikeInt_co,
170+
subscripts: str | _nt.CoInteger_nd,
177171
/,
178-
*operands: _ArrayLikeComplex_co | _DTypeLikeObject,
172+
*operands: _nt.CoComplex_nd | _DTypeLikeObject,
179173
optimize: _OptimizeKind = "greedy",
180174
einsum_call: L[False] = False,
181175
) -> 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, _ShapeLike
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: _ShapeLike | 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: _ShapeLike | 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)