Skip to content

Commit e020b23

Browse files
committed
TYP: work around a quantum-entangled mypy issue, somehow
1 parent 8a3c395 commit e020b23

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

numpy/_core/fromnumeric.pyi

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ from collections.abc import Sequence
33
from typing import (
44
Any,
55
Literal,
6-
NoReturn,
76
Protocol,
87
SupportsIndex,
98
TypeAlias,
109
TypeVar,
1110
overload,
1211
type_check_only,
1312
)
13+
14+
from _typeshed import Incomplete
1415
from typing_extensions import Never, deprecated
1516

1617
import numpy as np
@@ -556,9 +557,6 @@ def ravel(
556557
@overload
557558
def ravel(a: ArrayLike, order: _OrderKACF = "C") -> np.ndarray[tuple[int], np.dtype[Any]]: ...
558559

559-
@overload
560-
def nonzero(a: np.generic | np.ndarray[tuple[()], Any]) -> NoReturn: ...
561-
@overload
562560
def nonzero(a: _ArrayLike[Any]) -> tuple[NDArray[intp], ...]: ...
563561

564562
# this prevents `Any` from being returned with Pyright
@@ -818,7 +816,7 @@ def all(
818816
keepdims: _BoolLike_co | _NoValueType = ...,
819817
*,
820818
where: _ArrayLikeBool_co | _NoValueType = ...,
821-
) -> np.bool | NDArray[np.bool]: ...
819+
) -> Incomplete: ...
822820
@overload
823821
def all(
824822
a: ArrayLike,
@@ -855,7 +853,7 @@ def any(
855853
keepdims: _BoolLike_co | _NoValueType = ...,
856854
*,
857855
where: _ArrayLikeBool_co | _NoValueType = ...,
858-
) -> np.bool | NDArray[np.bool]: ...
856+
) -> Incomplete: ...
859857
@overload
860858
def any(
861859
a: ArrayLike,
@@ -1448,10 +1446,10 @@ def mean(
14481446
keepdims: Literal[False] | _NoValueType = ...,
14491447
*,
14501448
where: _ArrayLikeBool_co | _NoValueType = ...,
1451-
) -> complexfloating[Any, Any]: ...
1449+
) -> complexfloating[Any]: ...
14521450
@overload
14531451
def mean(
1454-
a: _ArrayLikeTD64_co,
1452+
a: _ArrayLike[np.timedelta64],
14551453
axis: None = ...,
14561454
dtype: None = ...,
14571455
out: None = ...,
@@ -1462,23 +1460,33 @@ def mean(
14621460
@overload
14631461
def mean(
14641462
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
1465-
axis: _ShapeLike | None = ...,
1466-
dtype: None = ...,
1467-
out: None = ...,
1463+
axis: _ShapeLike | None,
1464+
dtype: DTypeLike,
1465+
out: _ArrayT,
14681466
keepdims: bool | _NoValueType = ...,
14691467
*,
14701468
where: _ArrayLikeBool_co | _NoValueType = ...,
1471-
) -> Any: ...
1469+
) -> _ArrayT: ...
1470+
@overload
1471+
def mean(
1472+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
1473+
axis: _ShapeLike | None = ...,
1474+
dtype: DTypeLike | None = ...,
1475+
*,
1476+
out: _ArrayT,
1477+
keepdims: bool | _NoValueType = ...,
1478+
where: _ArrayLikeBool_co | _NoValueType = ...,
1479+
) -> _ArrayT: ...
14721480
@overload
14731481
def mean(
14741482
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
14751483
axis: None,
14761484
dtype: _DTypeLike[_SCT],
14771485
out: None = ...,
1478-
keepdims: bool | _NoValueType = ...,
1486+
keepdims: Literal[False] | _NoValueType = ...,
14791487
*,
14801488
where: _ArrayLikeBool_co | _NoValueType = ...,
1481-
) -> _SCT | NDArray[_SCT]: ...
1489+
) -> _SCT: ...
14821490
@overload
14831491
def mean(
14841492
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
@@ -1492,43 +1500,43 @@ def mean(
14921500
@overload
14931501
def mean(
14941502
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
1495-
axis: None = ...,
1496-
*,
1503+
axis: _ShapeLike | None,
14971504
dtype: _DTypeLike[_SCT],
1498-
out: None = ...,
1499-
keepdims: bool | _NoValueType = ...,
1505+
out: None,
1506+
keepdims: Literal[True, 1],
1507+
*,
15001508
where: _ArrayLikeBool_co | _NoValueType = ...,
1501-
) -> _SCT | NDArray[_SCT]: ...
1509+
) -> NDArray[_SCT]: ...
15021510
@overload
15031511
def mean(
15041512
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
1505-
axis: _ShapeLike | None = ...,
1506-
dtype: DTypeLike = ...,
1513+
axis: _ShapeLike | None,
1514+
dtype: _DTypeLike[_SCT],
15071515
out: None = ...,
1508-
keepdims: bool | _NoValueType = ...,
15091516
*,
1517+
keepdims: bool | _NoValueType = ...,
15101518
where: _ArrayLikeBool_co | _NoValueType = ...,
1511-
) -> Any: ...
1519+
) -> _SCT | NDArray[_SCT]: ...
15121520
@overload
15131521
def mean(
15141522
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
1515-
axis: _ShapeLike | None,
1516-
dtype: DTypeLike,
1517-
out: _ArrayT,
1518-
keepdims: bool | _NoValueType = ...,
1523+
axis: _ShapeLike | None = ...,
15191524
*,
1525+
dtype: _DTypeLike[_SCT],
1526+
out: None = ...,
1527+
keepdims: bool | _NoValueType = ...,
15201528
where: _ArrayLikeBool_co | _NoValueType = ...,
1521-
) -> _ArrayT: ...
1529+
) -> _SCT | NDArray[_SCT]: ...
15221530
@overload
15231531
def mean(
15241532
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
15251533
axis: _ShapeLike | None = ...,
1526-
dtype: DTypeLike = ...,
1527-
*,
1528-
out: _ArrayT,
1534+
dtype: DTypeLike | None = ...,
1535+
out: None = ...,
15291536
keepdims: bool | _NoValueType = ...,
1537+
*,
15301538
where: _ArrayLikeBool_co | _NoValueType = ...,
1531-
) -> _ArrayT: ...
1539+
) -> Incomplete: ...
15321540

15331541
@overload
15341542
def std(

numpy/typing/tests/data/reveal/fromnumeric.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for :mod:`_core.fromnumeric`."""
22

3-
from typing import Any, Literal as L, NoReturn
3+
from typing import Any, Literal as L
44

55
import numpy as np
66
import numpy.typing as npt
@@ -126,11 +126,8 @@ assert_type(np.ravel(f), np.ndarray[tuple[int], np.dtype[np.float64 | np.int_ |
126126
assert_type(np.ravel(AR_b), np.ndarray[tuple[int], np.dtype[np.bool]])
127127
assert_type(np.ravel(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])
128128

129-
assert_type(np.nonzero(b), NoReturn)
130-
assert_type(np.nonzero(f4), NoReturn)
131129
assert_type(np.nonzero(AR_b), tuple[npt.NDArray[np.intp], ...])
132130
assert_type(np.nonzero(AR_f4), tuple[npt.NDArray[np.intp], ...])
133-
assert_type(np.nonzero(AR_0d), NoReturn)
134131
assert_type(np.nonzero(AR_1d), tuple[npt.NDArray[np.intp], ...])
135132
assert_type(np.nonzero(AR_nd), tuple[npt.NDArray[np.intp], ...])
136133

0 commit comments

Comments
 (0)