Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/numpy-stubs/@test/runtime/legacy/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
AR2 % td

divmod(td, td) # pyright: ignore[reportArgumentType, reportCallIssue] # microsoft/pyright#10899
divmod(td, AR2)
divmod(td, AR2) # pyright: ignore[reportCallIssue] # microsoft/pyright#10899
divmod(AR2, td)

# Bool
Expand All @@ -49,7 +49,7 @@
divmod(b, i8)
divmod(b, u8)
divmod(b_, f8)
divmod(b_, AR)
divmod(b_, AR) # pyright: ignore[reportCallIssue] # microsoft/pyright#10899

b % b_
i % b_
Expand Down Expand Up @@ -91,7 +91,7 @@
divmod(i8, f4)
divmod(i4, i4)
divmod(i4, f4)
divmod(i8, AR)
divmod(i8, AR) # pyright: ignore[reportCallIssue] # microsoft/pyright#10899

b % i8
i % i8
Expand Down Expand Up @@ -130,7 +130,7 @@
divmod(f8, f8)
divmod(f8, f4)
divmod(f4, f4)
divmod(f8, AR)
divmod(f8, AR) # pyright: ignore[reportCallIssue] # microsoft/pyright#10899

b % f8
i % f8
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/@test/runtime/legacy/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def iterable_func(x: Iterable[object]) -> Iterable[object]:
array %= 1

divmod(array, 1) # pyright: ignore[reportArgumentType, reportCallIssue] # microsoft/pyright#10899
divmod(1, nonzero_array)
divmod(1, nonzero_array) # pyright: ignore[reportCallIssue] # microsoft/pyright#10899

array**1
1**array
Expand Down
8 changes: 4 additions & 4 deletions src/numpy-stubs/@test/static/accept/mod.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ assert_type(divmod(m_td, m_int), tuple[np.int64, np.timedelta64[int | None]]) #
assert_type(divmod(m_td, m_td), tuple[np.int64, np.timedelta64[dt.timedelta | None]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]

assert_type(divmod(AR_m, m), tuple[_nt.Array[np.int64], _nt.Array[np.timedelta64]])
assert_type(divmod(m, AR_m), tuple[_nt.Array[np.int64], _nt.Array[np.timedelta64]])
assert_type(divmod(m, AR_m), tuple[_nt.Array[np.int64], _nt.Array[np.timedelta64]]) # pyright: ignore[reportAssertTypeFailure, reportCallIssue]

# Bool
assert_type(b_ % b, np.int8)
Expand All @@ -90,7 +90,7 @@ assert_type(divmod(b_, f), tuple[np.float64, np.float64]) # pyright: ignore[rep
assert_type(divmod(b_, i8), tuple[np.int64, np.int64])
assert_type(divmod(b_, u8), tuple[np.uint64, np.uint64])
assert_type(divmod(b_, f8), tuple[np.float64, np.float64])
assert_type(divmod(b_, AR_b), tuple[_nt.Array[np.int8], _nt.Array[np.int8]])
assert_type(divmod(b_, AR_b), tuple[_nt.Array[np.int8], _nt.Array[np.int8]]) # pyright: ignore[reportAssertTypeFailure, reportCallIssue]

assert_type(b % b_, np.int8)
assert_type(i % b_, np.intp)
Expand Down Expand Up @@ -130,7 +130,7 @@ assert_type(divmod(i8, i8), tuple[np.int64, np.int64])
assert_type(divmod(i8, f8), tuple[np.float64, np.float64])
assert_type(divmod(i8, f4), tuple[np.float64, np.float64])
assert_type(divmod(i4, i4), tuple[np.int32, np.int32])
assert_type(divmod(i8, AR_b), tuple[_nt.Array[np.int64], _nt.Array[np.int64]])
assert_type(divmod(i8, AR_b), tuple[_nt.Array[np.int64], _nt.Array[np.int64]]) # pyright: ignore[reportAssertTypeFailure, reportCallIssue]

assert_type(b % i8, np.int64)
assert_type(f % i8, np.float64)
Expand Down Expand Up @@ -165,7 +165,7 @@ assert_type(divmod(f8, f), tuple[np.float64, np.float64])
assert_type(divmod(f8, f8), tuple[np.float64, np.float64])
assert_type(divmod(f8, f4), tuple[np.float64, np.float64])
assert_type(divmod(f4, f4), tuple[np.float32, np.float32])
assert_type(divmod(f8, AR_b), tuple[_nt.Array[np.float64], _nt.Array[np.float64]])
assert_type(divmod(f8, AR_b), tuple[_nt.Array[np.float64], _nt.Array[np.float64]]) # pyright: ignore[reportAssertTypeFailure, reportCallIssue]

assert_type(b % f8, np.float64)
assert_type(f % f8, np.float64) # pyright: ignore[reportAssertTypeFailure] # pyright incorrectly infers `float`
Expand Down
44 changes: 24 additions & 20 deletions src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,9 @@ _NumericArrayT = TypeVar("_NumericArrayT", bound=_nt.Array[number | timedelta64

_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape)
_ShapeT2 = TypeVar("_ShapeT2", bound=_nt.Shape)
# TODO(jorenham): use `Shape` instead of `AnyShape` once python/mypy#19110 is fixed
_ShapeT_co = TypeVar("_ShapeT_co", bound=_nt.AnyShape, covariant=True)
# TODO(jorenham): use `Shape` instead of `AnyShape` as bound once python/mypy#19110 is fixed
_ShapeT_co = TypeVar("_ShapeT_co", bound=_nt.AnyShape, default=_nt.AnyShape, covariant=True)
_ShapeT0_co = TypeVar("_ShapeT0_co", bound=_nt.AnyShape, covariant=True)
_Shape1NDT = TypeVar("_Shape1NDT", bound=_nt.Shape1N)

_ScalarT = TypeVar("_ScalarT", bound=generic)
Expand Down Expand Up @@ -884,9 +885,9 @@ class _CanItem(Protocol[_T_co]):
def item(self, /) -> _T_co: ...

@type_check_only
class _HasShapeAndItem(Protocol[_ShapeT_co, _T_co]):
class _HasShapeAndItem(Protocol[_ShapeT0_co, _T_co]):
@property
def __inner_shape__(self, /) -> _ShapeT_co: ...
def __inner_shape__(self, /) -> _ShapeT0_co: ...
def item(self, /) -> _T_co: ...

@type_check_only
Expand All @@ -895,9 +896,9 @@ class _HasDType(Protocol[_T_co]):
def dtype(self, /) -> _T_co: ...

@type_check_only
class _HasShapeAndDType(Protocol[_ShapeT_co, _T_co]):
class _HasShapeAndDType(Protocol[_ShapeT0_co, _T_co]):
@property
def __inner_shape__(self, /) -> _ShapeT_co: ...
def __inner_shape__(self, /) -> _ShapeT0_co: ...
@property
def dtype(self, /) -> _T_co: ...

Expand Down Expand Up @@ -1920,6 +1921,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
def __pos__(self: _NumericArrayT, /) -> _NumericArrayT: ... # noqa: PYI019
def __invert__(self: _IntegralArrayT, /) -> _IntegralArrayT: ... # noqa: PYI019

# NOTE: The pyright `reportOverlappingOverload` errors below are false positives that
# started appearing after adding a default to `_ShapeT_co`

#
@overload
def __add__(self: _nt.Array[_ScalarT], x: _nt.Casts[_ScalarT], /) -> _nt.Array[_ScalarT]: ...
Expand All @@ -1936,11 +1940,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __add__(self: _nt.Array[datetime64], x: _nt.CoTimeDelta_nd, /) -> _nt.Array[datetime64]: ...
@overload
def __add__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ...
def __add__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __add__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match]
def __add__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
@overload
def __add__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ...
def __add__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __add__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ...
@overload
Expand All @@ -1964,11 +1968,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __radd__(self: _nt.Array[datetime64], x: _nt.CoTimeDelta_nd, /) -> _nt.Array[datetime64]: ...
@overload
def __radd__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ...
def __radd__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __radd__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match]
def __radd__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
@overload
def __radd__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ...
def __radd__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __radd__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ...
@overload
Expand Down Expand Up @@ -2020,7 +2024,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __sub__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ...
@overload
def __sub__(
def __sub__( # pyright: ignore[reportOverlappingOverload]
self: _nt.Array[number[_AnyNumberItemT]], x: _nt.Sequence1ND[_nt.op.CanRSub[_AnyNumberItemT]], /
) -> _nt.Array[Incomplete]: ...

Expand All @@ -2044,7 +2048,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __rsub__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ...
@overload
def __rsub__(
def __rsub__( # pyright: ignore[reportOverlappingOverload]
self: _nt.Array[number[_AnyNumberItemT]], x: _nt.Sequence1ND[_nt.op.CanSub[_AnyNumberItemT]], /
) -> _nt.Array[Incomplete]: ...

Expand Down Expand Up @@ -2082,11 +2086,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __mul__(self: _nt.CastsWithComplex[_ScalarT], x: _PyComplexND, /) -> _nt.Array[_ScalarT]: ...
@overload
def __mul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ...
def __mul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __mul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match]
def __mul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
@overload
def __mul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ...
def __mul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __mul__(self: _nt.StringArrayND[_T], x: _nt.ToInteger_nd, /) -> _nt.StringArrayND[_T]: ...
@overload
Expand All @@ -2108,11 +2112,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __rmul__(self: _nt.CastsWithComplex[_ScalarT], x: _PyComplexND, /) -> _nt.Array[_ScalarT]: ...
@overload
def __rmul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ...
def __rmul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __rmul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match]
def __rmul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
@overload
def __rmul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ...
def __rmul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... # pyright: ignore[reportOverlappingOverload]
@overload
def __rmul__(self: _nt.StringArrayND[_T], x: _nt.ToInteger_nd, /) -> _nt.StringArrayND[_T]: ...
@overload
Expand Down