Skip to content

Commit c11ed75

Browse files
authored
♻️ Move _ShapeLike from numpy._typing to _numtype.ToShape (#854)
1 parent 5aa5359 commit c11ed75

22 files changed

Lines changed: 648 additions & 636 deletions

src/_numtype/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ from ._shape import (
154154
Shape3N as Shape3N,
155155
Shape4 as Shape4,
156156
Shape4N as Shape4N,
157+
ToShape as ToShape,
157158
)
158159

159160
###

src/_numtype/_shape.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Never, TypeAlias
1+
from collections.abc import Sequence
2+
from typing import Any, Never, SupportsIndex, TypeAlias
23
from typing_extensions import TypeAliasType
34

45
__all__ = [
@@ -16,6 +17,7 @@ __all__ = [
1617
"Shape4",
1718
"Shape4N",
1819
"ShapeN",
20+
"ToShape",
1921
]
2022

2123
Shape = TypeAliasType("Shape", tuple[int, ...])
@@ -35,3 +37,5 @@ Shape1N = TypeAliasType("Shape1N", tuple[int, *tuple[int, ...]])
3537
Shape2N = TypeAliasType("Shape2N", tuple[int, int, *tuple[int, ...]])
3638
Shape3N = TypeAliasType("Shape3N", tuple[int, int, int, *tuple[int, ...]])
3739
Shape4N = TypeAliasType("Shape4N", tuple[int, int, int, int, *tuple[int, ...]])
40+
41+
ToShape: TypeAlias = SupportsIndex | Sequence[SupportsIndex]

src/numpy-stubs/__init__.pyi

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ from ._typing import (
346346
_NestedSequence,
347347
_NumberLike_co,
348348
_ScalarLike_co,
349-
_ShapeLike,
350349
_TD64Like_co,
351350
)
352351
from .lib import scimath as emath
@@ -1322,7 +1321,7 @@ class _ArrayOrScalarCommon:
13221321
def copy(self, order: _OrderKACF = ...) -> Self: ...
13231322
def __copy__(self) -> Self: ...
13241323
def __deepcopy__(self, memo: dict[int, Any] | None, /) -> Self: ...
1325-
def __setstate__(self, state: tuple[CanIndex, _ShapeLike, _DTypeT_co, bool_, bytes | list[Any]], /) -> None: ...
1324+
def __setstate__(self, state: tuple[CanIndex, _nt.ToShape, _DTypeT_co, bool_, bytes | list[Any]], /) -> None: ...
13261325
def __array_namespace__(self, /, *, api_version: _ArrayAPIVersion | None = None) -> ModuleType: ...
13271326

13281327
#
@@ -1351,7 +1350,7 @@ class _ArrayOrScalarCommon:
13511350
def max(
13521351
self,
13531352
/,
1354-
axis: _ShapeLike | None = None,
1353+
axis: _nt.ToShape | None = None,
13551354
out: None = None,
13561355
*,
13571356
keepdims: py_bool | _NoValueType = ...,
@@ -1362,7 +1361,7 @@ class _ArrayOrScalarCommon:
13621361
def max(
13631362
self,
13641363
/,
1365-
axis: _ShapeLike | None,
1364+
axis: _nt.ToShape | None,
13661365
out: _ArrayT,
13671366
*,
13681367
keepdims: py_bool | _NoValueType = ...,
@@ -1373,7 +1372,7 @@ class _ArrayOrScalarCommon:
13731372
def max(
13741373
self,
13751374
/,
1376-
axis: _ShapeLike | None = None,
1375+
axis: _nt.ToShape | None = None,
13771376
*,
13781377
out: _ArrayT,
13791378
keepdims: py_bool | _NoValueType = ...,
@@ -1396,7 +1395,7 @@ class _ArrayOrScalarCommon:
13961395
def min(
13971396
self,
13981397
/,
1399-
axis: _ShapeLike | None = None,
1398+
axis: _nt.ToShape | None = None,
14001399
out: None = None,
14011400
*,
14021401
keepdims: py_bool | _NoValueType = ...,
@@ -1407,7 +1406,7 @@ class _ArrayOrScalarCommon:
14071406
def min(
14081407
self,
14091408
/,
1410-
axis: _ShapeLike | None,
1409+
axis: _nt.ToShape | None,
14111410
out: _ArrayT,
14121411
*,
14131412
keepdims: py_bool | _NoValueType = ...,
@@ -1418,7 +1417,7 @@ class _ArrayOrScalarCommon:
14181417
def min(
14191418
self,
14201419
/,
1421-
axis: _ShapeLike | None = None,
1420+
axis: _nt.ToShape | None = None,
14221421
*,
14231422
out: _ArrayT,
14241423
keepdims: py_bool | _NoValueType = ...,
@@ -1492,7 +1491,7 @@ class _ArrayOrScalarCommon:
14921491
def sum(
14931492
self,
14941493
/,
1495-
axis: _ShapeLike | None = None,
1494+
axis: _nt.ToShape | None = None,
14961495
dtype: DTypeLike | None = None,
14971496
out: None = None,
14981497
*,
@@ -1504,7 +1503,7 @@ class _ArrayOrScalarCommon:
15041503
def sum(
15051504
self,
15061505
/,
1507-
axis: _ShapeLike | None,
1506+
axis: _nt.ToShape | None,
15081507
dtype: DTypeLike | None,
15091508
out: _ArrayT,
15101509
*,
@@ -1516,7 +1515,7 @@ class _ArrayOrScalarCommon:
15161515
def sum(
15171516
self,
15181517
/,
1519-
axis: _ShapeLike | None = None,
1518+
axis: _nt.ToShape | None = None,
15201519
dtype: DTypeLike | None = None,
15211520
*,
15221521
out: _ArrayT,
@@ -1540,7 +1539,7 @@ class _ArrayOrScalarCommon:
15401539
def prod(
15411540
self,
15421541
/,
1543-
axis: _ShapeLike | None = None,
1542+
axis: _nt.ToShape | None = None,
15441543
dtype: DTypeLike | None = None,
15451544
out: None = None,
15461545
*,
@@ -1552,7 +1551,7 @@ class _ArrayOrScalarCommon:
15521551
def prod(
15531552
self,
15541553
/,
1555-
axis: _ShapeLike | None,
1554+
axis: _nt.ToShape | None,
15561555
dtype: DTypeLike | None,
15571556
out: _ArrayT,
15581557
*,
@@ -1564,7 +1563,7 @@ class _ArrayOrScalarCommon:
15641563
def prod(
15651564
self,
15661565
/,
1567-
axis: _ShapeLike | None = None,
1566+
axis: _nt.ToShape | None = None,
15681567
dtype: DTypeLike | None = None,
15691568
*,
15701569
out: _ArrayT,
@@ -1577,7 +1576,7 @@ class _ArrayOrScalarCommon:
15771576
@overload
15781577
def mean(
15791578
self,
1580-
axis: _ShapeLike | None = None,
1579+
axis: _nt.ToShape | None = None,
15811580
dtype: DTypeLike | None = None,
15821581
out: None = None,
15831582
*,
@@ -1588,7 +1587,7 @@ class _ArrayOrScalarCommon:
15881587
def mean(
15891588
self,
15901589
/,
1591-
axis: _ShapeLike | None,
1590+
axis: _nt.ToShape | None,
15921591
dtype: DTypeLike | None,
15931592
out: _ArrayT,
15941593
*,
@@ -1599,7 +1598,7 @@ class _ArrayOrScalarCommon:
15991598
def mean(
16001599
self,
16011600
/,
1602-
axis: _ShapeLike | None = None,
1601+
axis: _nt.ToShape | None = None,
16031602
dtype: DTypeLike | None = None,
16041603
*,
16051604
out: _ArrayT,
@@ -1611,7 +1610,7 @@ class _ArrayOrScalarCommon:
16111610
@overload
16121611
def std(
16131612
self,
1614-
axis: _ShapeLike | None = None,
1613+
axis: _nt.ToShape | None = None,
16151614
dtype: DTypeLike | None = None,
16161615
out: None = None,
16171616
ddof: float = 0,
@@ -1624,7 +1623,7 @@ class _ArrayOrScalarCommon:
16241623
@overload
16251624
def std(
16261625
self,
1627-
axis: _ShapeLike | None,
1626+
axis: _nt.ToShape | None,
16281627
dtype: DTypeLike | None,
16291628
out: _ArrayT,
16301629
ddof: float = 0,
@@ -1637,7 +1636,7 @@ class _ArrayOrScalarCommon:
16371636
@overload
16381637
def std(
16391638
self,
1640-
axis: _ShapeLike | None = None,
1639+
axis: _nt.ToShape | None = None,
16411640
dtype: DTypeLike | None = None,
16421641
*,
16431642
out: _ArrayT,
@@ -1652,7 +1651,7 @@ class _ArrayOrScalarCommon:
16521651
@overload
16531652
def var(
16541653
self,
1655-
axis: _ShapeLike | None = None,
1654+
axis: _nt.ToShape | None = None,
16561655
dtype: DTypeLike | None = None,
16571656
out: None = None,
16581657
ddof: float = 0,
@@ -1665,7 +1664,7 @@ class _ArrayOrScalarCommon:
16651664
@overload
16661665
def var(
16671666
self,
1668-
axis: _ShapeLike | None,
1667+
axis: _nt.ToShape | None,
16691668
dtype: DTypeLike | None,
16701669
out: _ArrayT,
16711670
ddof: float = 0,
@@ -1678,7 +1677,7 @@ class _ArrayOrScalarCommon:
16781677
@overload
16791678
def var(
16801679
self,
1681-
axis: _ShapeLike | None = None,
1680+
axis: _nt.ToShape | None = None,
16821681
dtype: DTypeLike | None = None,
16831682
*,
16841683
out: _ArrayT,
@@ -1751,11 +1750,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
17511750
#
17521751
def __new__(
17531752
cls,
1754-
shape: _ShapeLike,
1753+
shape: _nt.ToShape,
17551754
dtype: DTypeLike | None = float, # noqa: PYI011
17561755
buffer: Buffer | None = None,
17571756
offset: CanIndex = 0,
1758-
strides: _ShapeLike | None = None,
1757+
strides: _nt.ToShape | None = None,
17591758
order: _OrderKACF | None = None,
17601759
) -> Self: ...
17611760

@@ -2775,7 +2774,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27752774

27762775
#
27772776
@overload
2778-
def transpose(self, axes: _ShapeLike | None, /) -> Self: ...
2777+
def transpose(self, axes: _nt.ToShape | None, /) -> Self: ...
27792778
@overload
27802779
def transpose(self, /, *axes: CanIndex) -> Self: ...
27812780

0 commit comments

Comments
 (0)