Skip to content

Commit f50c41f

Browse files
committed
🩹 prefer _nt.Rank* over _nt.Shape* as return type, and the other way around for input types
1 parent b194987 commit f50c41f

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

‎src/numpy-stubs/_core/_multiarray_umath.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def empty(
505505
dtype: _DTypeT | _HasDType[_DTypeT],
506506
order: _OrderCF = "C",
507507
**kwargs: Unpack[_KwargsDL],
508-
) -> np.ndarray[_nt.Shape1, _DTypeT]: ...
508+
) -> np.ndarray[_nt.Rank1, _DTypeT]: ...
509509
@overload # 1d shape, known scalar-type
510510
def empty(
511511
shape: _ShapeLike1D,
@@ -561,7 +561,7 @@ def empty(
561561
dtype: _DTypeT | _HasDType[_DTypeT],
562562
order: _OrderCF = "C",
563563
**kwargs: Unpack[_KwargsDL],
564-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
564+
) -> np.ndarray[Incomplete, _DTypeT]: ...
565565
@overload # unknown shape, known scalar-type
566566
def empty(
567567
shape: _ShapeLike,
@@ -591,7 +591,7 @@ def zeros(
591591
dtype: _DTypeT | _HasDType[_DTypeT],
592592
order: _OrderCF = "C",
593593
**kwargs: Unpack[_KwargsDL],
594-
) -> np.ndarray[_nt.Shape1, _DTypeT]: ...
594+
) -> np.ndarray[_nt.Rank1, _DTypeT]: ...
595595
@overload # 1d shape, known scalar-type
596596
def zeros(
597597
shape: _ShapeLike1D,
@@ -647,7 +647,7 @@ def zeros(
647647
dtype: _DTypeT | _HasDType[_DTypeT],
648648
order: _OrderCF = "C",
649649
**kwargs: Unpack[_KwargsDL],
650-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
650+
) -> np.ndarray[Incomplete, _DTypeT]: ...
651651
@overload # unknown shape, known scalar-type
652652
def zeros(
653653
shape: _ShapeLike,
@@ -875,15 +875,15 @@ def empty_like( # type: ignore[overload-overlap]
875875
device: _Device | None = None,
876876
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
877877
@overload # unknown shape, given dtype
878-
def empty_like( # type: ignore[overload-overlap]
878+
def empty_like(
879879
prototype: object,
880880
dtype: _DTypeT | _HasDType[_DTypeT],
881881
order: _OrderKACF = "K",
882882
subok: bool = True,
883883
shape: _ShapeLike | None = None,
884884
*,
885885
device: _Device | None = None,
886-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
886+
) -> np.ndarray[Incomplete, _DTypeT]: ...
887887
@overload # given shape, given scalar-type
888888
def empty_like(
889889
prototype: object,

‎src/numpy-stubs/_core/numeric.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def ones(
642642
*,
643643
device: _Device | None = None,
644644
like: _SupportsArrayFunc | None = None,
645-
) -> np.ndarray[_nt.Shape1, _DTypeT]: ...
645+
) -> np.ndarray[_nt.Rank1, _DTypeT]: ...
646646
@overload # 1d shape, known scalar-type
647647
def ones(
648648
shape: _ShapeLike1D,
@@ -714,7 +714,7 @@ def ones(
714714
*,
715715
device: _Device | None = None,
716716
like: _SupportsArrayFunc | None = None,
717-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
717+
) -> np.ndarray[Any, _DTypeT]: ...
718718
@overload # unknown shape, known scalar-type
719719
def ones(
720720
shape: _ShapeLike,
@@ -796,7 +796,7 @@ def full(
796796
*,
797797
device: _Device | None = None,
798798
like: _SupportsArrayFunc | None = None,
799-
) -> np.ndarray[_nt.Shape1, _DTypeT]: ...
799+
) -> np.ndarray[_nt.Rank1, _DTypeT]: ...
800800
@overload # 1d shape, known scalar-type
801801
def full(
802802
shape: _ShapeLike1D,
@@ -976,7 +976,7 @@ def full(
976976
*,
977977
device: _Device | None = None,
978978
like: _SupportsArrayFunc | None = None,
979-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
979+
) -> np.ndarray[Any, _DTypeT]: ...
980980
@overload # unknown shape, known scalar-type
981981
def full(
982982
shape: _ShapeLike,
@@ -1220,15 +1220,15 @@ def zeros_like( # type: ignore[overload-overlap]
12201220
device: _Device | None = None,
12211221
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
12221222
@overload # unknown shape, given dtype
1223-
def zeros_like( # type: ignore[overload-overlap]
1223+
def zeros_like(
12241224
a: object,
12251225
dtype: _DTypeT | _SupportsDType[_DTypeT],
12261226
order: _OrderKACF = "K",
12271227
subok: py_bool = True,
12281228
shape: _ShapeLike | None = None,
12291229
*,
12301230
device: _Device | None = None,
1231-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
1231+
) -> np.ndarray[Any, _DTypeT]: ...
12321232
@overload # given shape, given scalar-type
12331233
def zeros_like(
12341234
a: object,
@@ -1522,15 +1522,15 @@ def ones_like( # type: ignore[overload-overlap]
15221522
device: _Device | None = None,
15231523
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
15241524
@overload # unknown shape, given dtype
1525-
def ones_like( # type: ignore[overload-overlap]
1525+
def ones_like(
15261526
a: object,
15271527
dtype: _DTypeT | _SupportsDType[_DTypeT],
15281528
order: _OrderKACF = "K",
15291529
subok: py_bool = True,
15301530
shape: _ShapeLike | None = None,
15311531
*,
15321532
device: _Device | None = None,
1533-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
1533+
) -> np.ndarray[Any, _DTypeT]: ...
15341534
@overload # given shape, given scalar-type
15351535
def ones_like(
15361536
a: object,
@@ -1845,7 +1845,7 @@ def full_like( # type: ignore[overload-overlap]
18451845
device: _Device | None = None,
18461846
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
18471847
@overload # unknown shape, given dtype
1848-
def full_like( # type: ignore[overload-overlap]
1848+
def full_like(
18491849
a: object,
18501850
fill_value: object,
18511851
dtype: _DTypeT | _SupportsDType[_DTypeT],
@@ -1854,7 +1854,7 @@ def full_like( # type: ignore[overload-overlap]
18541854
shape: _ShapeLike | None = None,
18551855
*,
18561856
device: _Device | None = None,
1857-
) -> np.ndarray[_nt.Shape, _DTypeT]: ...
1857+
) -> np.ndarray[Any, _DTypeT]: ...
18581858
@overload # given shape, given scalar-type
18591859
def full_like(
18601860
a: object,

‎src/numpy-stubs/matrixlib/defmatrix.pyi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
3636
@overload # type: ignore[override]
3737
def __getitem__(self, key: CanIndex | _ArrayLikeInt_co | tuple[CanIndex | _ArrayLikeInt_co, ...], /) -> Any: ...
3838
@overload
39-
def __getitem__(self, key: _ToIndex1 | _ToIndex2, /) -> matrix[_nt.Shape2, _DTypeT_co]: ...
39+
def __getitem__(self, key: _ToIndex1 | _ToIndex2, /) -> matrix[_nt.Rank2, _DTypeT_co]: ...
4040
@overload
4141
def __getitem__(self: _nt.Array[np.void], key: str, /) -> matrix[_ShapeT_co, np.dtype]: ...
4242
@overload
@@ -140,7 +140,7 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
140140
@overload # type: ignore[override]
141141
def max(self: _nt.Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ...
142142
@overload
143-
def max(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Shape2, _DTypeT_co]: ...
143+
def max(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Rank2, _DTypeT_co]: ...
144144
@overload
145145
def max(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ...
146146
@overload
@@ -150,7 +150,7 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
150150
@overload # type: ignore[override]
151151
def min(self: _nt.Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ...
152152
@overload
153-
def min(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Shape2, _DTypeT_co]: ...
153+
def min(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Rank2, _DTypeT_co]: ...
154154
@overload
155155
def min(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ...
156156
@overload
@@ -180,7 +180,7 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
180180
@overload # type: ignore[override]
181181
def ptp(self: _nt.Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ...
182182
@overload
183-
def ptp(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Shape2, _DTypeT_co]: ...
183+
def ptp(self, /, axis: _ToAxis, out: None = None) -> matrix[_nt.Rank2, _DTypeT_co]: ...
184184
@overload
185185
def ptp(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ...
186186
@overload
@@ -192,22 +192,22 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
192192

193193
#
194194
@override
195-
def squeeze(self, /, axis: _ToAxis | None = None) -> matrix[_nt.Shape2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
195+
def squeeze(self, /, axis: _ToAxis | None = None) -> matrix[_nt.Rank2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
196196
@override
197-
def ravel(self, /, order: _OrderKACF = "C") -> matrix[_nt.Shape2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
197+
def ravel(self, /, order: _OrderKACF = "C") -> matrix[_nt.Rank2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
198198
@override
199-
def flatten(self, /, order: _OrderKACF = "C") -> matrix[_nt.Shape2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
199+
def flatten(self, /, order: _OrderKACF = "C") -> matrix[_nt.Rank2, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
200200

201201
#
202202
@property
203203
@override
204-
def T(self) -> matrix[_nt.Shape2, _DTypeT_co]: ... # type: ignore[override]
205-
def getT(self) -> matrix[_nt.Shape2, _DTypeT_co]: ...
204+
def T(self) -> matrix[_nt.Rank2, _DTypeT_co]: ... # type: ignore[override]
205+
def getT(self) -> matrix[_nt.Rank2, _DTypeT_co]: ...
206206

207207
#
208208
@property
209-
def H(self) -> matrix[_nt.Shape2, _DTypeT_co]: ...
210-
def getH(self) -> matrix[_nt.Shape2, _DTypeT_co]: ...
209+
def H(self) -> matrix[_nt.Rank2, _DTypeT_co]: ...
210+
def getH(self) -> matrix[_nt.Rank2, _DTypeT_co]: ...
211211

212212
#
213213
@property
@@ -221,8 +221,8 @@ class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
221221

222222
#
223223
@property
224-
def A1(self) -> np.ndarray[_nt.Shape1, _DTypeT_co]: ...
225-
def getA1(self) -> np.ndarray[_nt.Shape1, _DTypeT_co]: ...
224+
def A1(self) -> np.ndarray[_nt.Rank1, _DTypeT_co]: ...
225+
def getA1(self) -> np.ndarray[_nt.Rank1, _DTypeT_co]: ...
226226

227227
#
228228
@overload

0 commit comments

Comments
 (0)