diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0558317..a7086c50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,13 +40,19 @@ jobs: run: uv run ruff format --check - name: basedpyright (numpy-stubs) - run: uv run basedpyright src/numpy-stubs/random + run: > + uv run basedpyright + src/numpy-stubs/_typing + src/numpy-stubs/random - name: basedpyright (test) - run: uv run basedpyright test/ + run: uv run basedpyright test - name: basedmypy (numpy-stubs) - run: uv run --no-editable mypy src/numpy-stubs/random + run: > + uv run --no-editable mypy + src/numpy-stubs/_typing + src/numpy-stubs/random - name: basedmypy (test) run: uv run test/bmp.py diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 483fff1c..703677d6 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -272,7 +272,6 @@ from numpy._typing import ( _VoidDTypeLike, ) from numpy._typing._callable import ( - _BoolBitOp, _BoolDivMod, _BoolMod, _BoolOp, @@ -285,11 +284,6 @@ from numpy._typing._callable import ( _FloatDivMod, _FloatMod, _FloatOp, - _IntTrueDiv, - _NumberOp, - _SignedIntBitOp, - _SignedIntDivMod, - _SignedIntMod, _SignedIntOp, _UnsignedIntBitOp, _UnsignedIntDivMod, @@ -3940,22 +3934,21 @@ class number(generic[_NumberItemT_co], Generic[_NBit, _NumberItemT_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... # - def __neg__(self) -> Self: ... - def __pos__(self) -> Self: ... - def __abs__(self) -> Self: ... - - __add__: _NumberOp - __radd__: _NumberOp - __sub__: _NumberOp - __rsub__: _NumberOp - __mul__: _NumberOp - __rmul__: _NumberOp - __floordiv__: _NumberOp - __rfloordiv__: _NumberOp - __pow__: _NumberOp - __rpow__: _NumberOp - __truediv__: _NumberOp - __rtruediv__: _NumberOp + def __neg__(self, /) -> Self: ... + def __pos__(self, /) -> Self: ... + def __abs__(self, /) -> Self: ... + def __add__(self, x: Any, /) -> Any: ... + def __radd__(self, x: Any, /) -> Any: ... + def __sub__(self, x: Any, /) -> Any: ... + def __rsub__(self, x: Any, /) -> Any: ... + def __mul__(self, x: Any, /) -> Any: ... + def __rmul__(self, x: Any, /) -> Any: ... + def __floordiv__(self, x: Any, /) -> Any: ... + def __rfloordiv__(self, x: Any, /) -> Any: ... + def __truediv__(self, x: Any, /) -> Any: ... + def __rtruediv__(self, x: Any, /) -> Any: ... + def __pow__(self, x: Any, /) -> Any: ... + def __rpow__(self, x: Any, /) -> Any: ... __lt__: _ComparisonOpLT[_NumberLike_co, _ArrayLikeNumber_co] __le__: _ComparisonOpLE[_NumberLike_co, _ArrayLikeNumber_co] @@ -3974,46 +3967,40 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): # @overload - def __init__(self: np.bool[L[False]], /) -> None: ... - @overload def __init__(self: np.bool[L[False]], value: _Falsy = ..., /) -> None: ... @overload def __init__(self: np.bool[L[True]], value: _Truthy, /) -> None: ... @overload - def __init__(self, value: object, /) -> None: ... + def __init__(self: np.bool[builtins.bool], value: object, /) -> None: ... # def __bool__(self, /) -> _BoolItemT_co: ... + # + @deprecated("In future, it will be an error for 'np.bool' scalars to be interpreted as an index") + def __index__(self, /) -> L[0, 1]: ... + # @overload def __int__(self: np.bool[L[False]], /) -> L[0]: ... @overload def __int__(self: np.bool[L[True]], /) -> L[1]: ... @overload - def __int__(self, /) -> L[0, 1]: ... + def __int__(self: np.bool[builtins.bool], /) -> L[0, 1]: ... - # - @deprecated("In future, it will be an error for 'np.bool' scalars to be interpreted as an index") - def __index__(self, /) -> L[0, 1]: ... + __lt__: _ComparisonOpLT[_NumberLike_co, _ArrayLikeNumber_co] + __le__: _ComparisonOpLE[_NumberLike_co, _ArrayLikeNumber_co] + __gt__: _ComparisonOpGT[_NumberLike_co, _ArrayLikeNumber_co] + __ge__: _ComparisonOpGE[_NumberLike_co, _ArrayLikeNumber_co] - # def __abs__(self) -> Self: ... - # - @overload - def __invert__(self: np.bool[L[False]], /) -> np.bool[L[True]]: ... - @overload - def __invert__(self: np.bool[L[True]], /) -> np.bool[L[False]]: ... - @overload - def __invert__(self, /) -> np.bool: ... - __add__: _BoolOp[np.bool] __radd__: _BoolOp[np.bool] - __sub__: _BoolSub - __rsub__: _BoolSub __mul__: _BoolOp[np.bool] __rmul__: _BoolOp[np.bool] + __sub__: _BoolSub + __rsub__: _BoolSub __truediv__: _BoolTrueDiv __rtruediv__: _BoolTrueDiv __floordiv__: _BoolOp[int8] @@ -4021,64 +4008,78 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): __pow__: _BoolOp[int8] __rpow__: _BoolOp[int8] - __lshift__: _BoolBitOp[int8] - __rlshift__: _BoolBitOp[int8] - __rshift__: _BoolBitOp[int8] - __rrshift__: _BoolBitOp[int8] + __mod__: _BoolMod + __rmod__: _BoolMod + __divmod__: _BoolDivMod + __rdivmod__: _BoolDivMod + + @overload + def __lshift__(self, x: _IntegerT, /) -> _IntegerT: ... + @overload + def __lshift__(self, x: builtins.bool | np.bool, /) -> np.int8: ... + @overload + def __lshift__(self, x: int, /) -> np.int8 | np.int_: ... + __rlshift__ = __lshift__ + + @overload + def __rshift__(self, x: _IntegerT, /) -> _IntegerT: ... + @overload + def __rshift__(self, x: builtins.bool | np.bool, /) -> np.int8: ... + @overload + def __rshift__(self, x: int, /) -> np.int8 | np.int_: ... + __rrshift__ = __rshift__ + + @overload + def __invert__(self: np.bool[L[False]], /) -> np.bool[L[True]]: ... + @overload + def __invert__(self: np.bool[L[True]], /) -> np.bool[L[False]]: ... + @overload + def __invert__(self, /) -> np.bool: ... + # @overload - def __and__(self: np.bool[L[False]], other: builtins.bool | np.bool, /) -> np.bool[L[False]]: ... + def __and__(self: np.bool[L[False]], x: builtins.bool | np.bool, /) -> np.bool[L[False]]: ... @overload - def __and__(self, other: L[False] | np.bool[L[False]], /) -> np.bool[L[False]]: ... + def __and__(self, x: L[False] | np.bool[L[False]], /) -> np.bool[L[False]]: ... @overload - def __and__(self, other: L[True] | np.bool[L[True]], /) -> Self: ... + def __and__(self, x: L[True] | np.bool[L[True]], /) -> Self: ... @overload - def __and__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __and__(self, x: builtins.bool | np.bool, /) -> np.bool: ... @overload - def __and__(self, other: _IntegerT, /) -> _IntegerT: ... + def __and__(self, x: _IntegerT, /) -> _IntegerT: ... @overload - def __and__(self, other: int, /) -> np.bool | intp: ... + def __and__(self, x: int, /) -> np.bool | intp: ... __rand__ = __and__ @overload - def __xor__(self: np.bool[L[False]], other: _BoolItemT | np.bool[_BoolItemT], /) -> np.bool[_BoolItemT]: ... + def __xor__(self: np.bool[L[False]], x: _BoolItemT | np.bool[_BoolItemT], /) -> np.bool[_BoolItemT]: ... @overload - def __xor__(self: np.bool[L[True]], other: L[True] | np.bool[L[True]], /) -> np.bool[L[False]]: ... + def __xor__(self: np.bool[L[True]], x: L[True] | np.bool[L[True]], /) -> np.bool[L[False]]: ... @overload - def __xor__(self, other: L[False] | np.bool[L[False]], /) -> Self: ... + def __xor__(self, x: L[False] | np.bool[L[False]], /) -> Self: ... @overload - def __xor__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __xor__(self, x: builtins.bool | np.bool, /) -> np.bool: ... @overload - def __xor__(self, other: _IntegerT, /) -> _IntegerT: ... + def __xor__(self, x: _IntegerT, /) -> _IntegerT: ... @overload - def __xor__(self, other: int, /) -> np.bool | intp: ... + def __xor__(self, x: int, /) -> np.bool | intp: ... __rxor__ = __xor__ @overload - def __or__(self: np.bool[L[True]], other: builtins.bool | np.bool, /) -> np.bool[L[True]]: ... + def __or__(self: np.bool[L[True]], x: builtins.bool | np.bool, /) -> np.bool[L[True]]: ... @overload - def __or__(self, other: L[False] | np.bool[L[False]], /) -> Self: ... + def __or__(self, x: L[False] | np.bool[L[False]], /) -> Self: ... @overload - def __or__(self, other: L[True] | np.bool[L[True]], /) -> np.bool[L[True]]: ... + def __or__(self, x: L[True] | np.bool[L[True]], /) -> np.bool[L[True]]: ... @overload - def __or__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __or__(self, x: builtins.bool | np.bool, /) -> np.bool: ... @overload - def __or__(self, other: _IntegerT, /) -> _IntegerT: ... + def __or__(self, x: _IntegerT, /) -> _IntegerT: ... @overload - def __or__(self, other: int, /) -> np.bool | intp: ... + def __or__(self, x: int, /) -> np.bool | intp: ... __ror__ = __or__ - __mod__: _BoolMod - __rmod__: _BoolMod - __divmod__: _BoolDivMod - __rdivmod__: _BoolDivMod - - __lt__: _ComparisonOpLT[_NumberLike_co, _ArrayLikeNumber_co] - __le__: _ComparisonOpLE[_NumberLike_co, _ArrayLikeNumber_co] - __gt__: _ComparisonOpGT[_NumberLike_co, _ArrayLikeNumber_co] - __ge__: _ComparisonOpGE[_NumberLike_co, _ArrayLikeNumber_co] - -# NOTE: This should _not_ be `Final` or a `TypeAlias` +# NOTE: This should NOT be `Final` or a `TypeAlias`! bool_ = bool # NOTE: The `object_` constructor returns the passed object, so instances with type @@ -4115,74 +4116,198 @@ class integer(_IntegralMixin, _RoundMixin, number[_NBit, int]): def __index__(self, /) -> int: ... # - __truediv__: _IntTrueDiv[_NBit] - __rtruediv__: _IntTrueDiv[_NBit] + def __invert__(self, /) -> Self: ... # - def __mod__(self, value: _IntLike_co, /) -> integer: ... - def __rmod__(self, value: _IntLike_co, /) -> integer: ... + @overload + def __truediv__(self, x: np.bool | integer | int | float, /) -> float64: ... + @overload + def __truediv__(self, x: int | float | complex, /) -> float64 | complex128: ... + # + @overload + def __rtruediv__(self, x: int | float, /) -> float64: ... + @overload + def __rtruediv__(self, x: int | float | complex, /) -> float64 | complex128: ... # - def __invert__(self, /) -> Self: ... + @overload + def __mod__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __mod__(self, x: float, /) -> Self | np.float64: ... + @overload + def __mod__(self, x: signedinteger, /) -> signedinteger: ... + @overload + def __mod__(self, x: _IntLike_co, /) -> integer: ... # - def __lshift__(self, other: _IntLike_co, /) -> integer: ... - def __rlshift__(self, other: _IntLike_co, /) -> integer: ... + @overload + def __rmod__(self, x: int, /) -> Self: ... + @overload + def __rmod__(self, x: int | float, /) -> Self | np.float64: ... # - def __rshift__(self, other: _IntLike_co, /) -> integer: ... - def __rrshift__(self, other: _IntLike_co, /) -> integer: ... + @overload + def __divmod__(self, x: Self | int8 | int | np.bool, /) -> _2Tuple[Self]: ... + @overload + def __divmod__(self, x: float, /) -> _2Tuple[Self] | _2Tuple[np.float64]: ... + @overload + def __divmod__(self, x: signedinteger, /) -> _2Tuple[signedinteger]: ... + @overload + def __divmod__(self, x: _IntLike_co, /) -> _2Tuple[integer]: ... # - def __and__(self, other: _IntLike_co, /) -> integer: ... - def __rand__(self, other: _IntLike_co, /) -> integer: ... + @overload + def __rdivmod__(self, x: int, /) -> _2Tuple[Self]: ... + @overload + def __rdivmod__(self, x: int | float, /) -> _2Tuple[Self] | _2Tuple[np.float64]: ... + + # + @overload + def __lshift__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __lshift__(self, x: _IntLike_co, /) -> integer: ... + def __rlshift__(self, x: int, /) -> Self: ... + + # + @overload + def __rshift__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __rshift__(self, x: _IntLike_co, /) -> integer: ... + def __rrshift__(self, x: int, /) -> Self: ... + + # + @overload + def __and__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __and__(self, x: _IntLike_co, /) -> integer: ... + def __rand__(self, x: int, /) -> Self: ... # - def __or__(self, other: _IntLike_co, /) -> integer: ... - def __ror__(self, other: _IntLike_co, /) -> integer: ... + @overload + def __or__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __or__(self, x: _IntLike_co, /) -> integer: ... + def __ror__(self, x: int, /) -> Self: ... # - def __xor__(self, other: _IntLike_co, /) -> integer: ... - def __rxor__(self, other: _IntLike_co, /) -> integer: ... + @overload + def __xor__(self, x: Self | int8 | int | np.bool, /) -> Self: ... + @overload + def __xor__(self, x: _IntLike_co, /) -> integer: ... + def __rxor__(self, x: int, /) -> Self: ... -class signedinteger(integer[_NBit1]): +class signedinteger(integer[_NBit]): def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ... - __add__: _SignedIntOp[_NBit1] - __radd__: _SignedIntOp[_NBit1] + __add__: _SignedIntOp[_NBit] + __radd__: _SignedIntOp[_NBit] - __sub__: _SignedIntOp[_NBit1] - __rsub__: _SignedIntOp[_NBit1] + __sub__: _SignedIntOp[_NBit] + __rsub__: _SignedIntOp[_NBit] - __mul__: _SignedIntOp[_NBit1] - __rmul__: _SignedIntOp[_NBit1] + __mul__: _SignedIntOp[_NBit] + __rmul__: _SignedIntOp[_NBit] - __floordiv__: _SignedIntOp[_NBit1] - __rfloordiv__: _SignedIntOp[_NBit1] + __floordiv__: _SignedIntOp[_NBit] + __rfloordiv__: _SignedIntOp[_NBit] - __pow__: _SignedIntOp[_NBit1] - __rpow__: _SignedIntOp[_NBit1] + __pow__: _SignedIntOp[_NBit] + __rpow__: _SignedIntOp[_NBit] - __lshift__: _SignedIntBitOp[_NBit1] - __rlshift__: _SignedIntBitOp[_NBit1] + @overload # type: ignore[override] + def __mod__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __mod__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __mod__(self: int64, x: float16 | float32 | float64, /) -> float64: ... + @overload + def __mod__(self, x: int64, /) -> int64: ... + @overload + def __mod__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __mod__(self, x: int | integer, /) -> signedinteger: ... + @overload + def __mod__(self, x: float64, /) -> float64: ... + @overload + def __mod__(self, x: int | float, /) -> Self | float64: ... # pyright: ignore[reportIncompatibleMethodOverride] - __rshift__: _SignedIntBitOp[_NBit1] - __rrshift__: _SignedIntBitOp[_NBit1] + # keep in sync with __mod__ + @overload # type: ignore[override] + def __divmod__(self, x: int | Self | int8 | np.bool, /) -> _2Tuple[Self]: ... + @overload + def __divmod__(self: int64, x: signedinteger, /) -> _2Tuple[int64]: ... + @overload + def __divmod__(self: int64, x: float16 | float32 | float64, /) -> _2Tuple[float64]: ... + @overload + def __divmod__(self, x: int64, /) -> _2Tuple[int64]: ... + @overload + def __divmod__(self, x: signedinteger[_NBit1], /) -> _2Tuple[signedinteger[_NBit | _NBit1]]: ... + @overload + def __divmod__(self, x: int | integer, /) -> _2Tuple[signedinteger]: ... + @overload + def __divmod__(self, x: float64, /) -> _2Tuple[float64]: ... + @overload + def __divmod__(self, x: int | float, /) -> _2Tuple[Self] | _2Tuple[float64]: ... # pyright: ignore[reportIncompatibleMethodOverride] - __and__: _SignedIntBitOp[_NBit1] - __rand__: _SignedIntBitOp[_NBit1] + # + @overload # type: ignore[override] + def __lshift__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __lshift__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __lshift__(self, x: int64, /) -> int64: ... + @overload + def __lshift__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __lshift__(self, x: _IntLike_co, /) -> np.signedinteger: ... # pyright: ignore[reportIncompatibleMethodOverride] - __xor__: _SignedIntBitOp[_NBit1] - __rxor__: _SignedIntBitOp[_NBit1] + # keep in sync with __lshift__ + @overload # type: ignore[override] + def __rshift__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __rshift__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __rshift__(self, x: int64, /) -> int64: ... + @overload + def __rshift__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __rshift__(self, x: _IntLike_co, /) -> np.signedinteger: ... # pyright: ignore[reportIncompatibleMethodOverride] - __or__: _SignedIntBitOp[_NBit1] - __ror__: _SignedIntBitOp[_NBit1] + # keep in sync with __lshift__ + @overload # type: ignore[override] + def __and__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __and__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __and__(self, x: int64, /) -> int64: ... + @overload + def __and__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __and__(self, x: _IntLike_co, /) -> np.signedinteger: ... # pyright: ignore[reportIncompatibleMethodOverride] - __mod__: _SignedIntMod[_NBit1] - __rmod__: _SignedIntMod[_NBit1] + # keep in sync with __lshift__ + @overload # type: ignore[override] + def __xor__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __xor__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __xor__(self, x: int64, /) -> int64: ... + @overload + def __xor__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __xor__(self, x: _IntLike_co, /) -> np.signedinteger: ... # pyright: ignore[reportIncompatibleMethodOverride] - __divmod__: _SignedIntDivMod[_NBit1] - __rdivmod__: _SignedIntDivMod[_NBit1] + # keep in sync with __lshift__ + @overload # type: ignore[override] + def __or__(self, x: int | Self | int8 | np.bool, /) -> Self: ... + @overload + def __or__(self: int64, x: signedinteger, /) -> int64: ... + @overload + def __or__(self, x: int64, /) -> int64: ... + @overload + def __or__(self, x: signedinteger[_NBit1], /) -> signedinteger[_NBit | _NBit1]: ... + @overload + def __or__(self, x: _IntLike_co, /) -> signedinteger: ... # pyright: ignore[reportIncompatibleMethodOverride] int8: TypeAlias = signedinteger[_8Bit] int16: TypeAlias = signedinteger[_16Bit] @@ -4430,6 +4555,8 @@ longdouble: TypeAlias = floating[_NBitLongDouble] # It is used to clarify why `complex128`s precision is `_64Bit`, the latter # describing the two 64 bit floats representing its real and imaginary component +_BinOperandComplex128_co: TypeAlias = complex | int32 | int64 | uint32 | uint64 | float64 + class complexfloating(inexact[_NBit1, complex], Generic[_NBit1, _NBit2]): @property def real(self) -> floating[_NBit1]: ... @@ -4462,83 +4589,113 @@ class complexfloating(inexact[_NBit1, complex], Generic[_NBit1, _NBit2]): # @overload - def __add__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __add__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __add__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __add__(self, other: complex | float64 | complex128, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __add__(self, other: complex | float64, /) -> Self | complex128: ... # type: ignore[overload-overlap] @overload - def __add__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __add__(self, other: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __add__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __radd__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __radd__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __radd__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __radd__(self, other: complex, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __radd__(self, other: complex, /) -> Self | complex128: ... @overload - def __radd__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __radd__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __sub__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __sub__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __sub__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __sub__(self, other: complex | float64 | complex128, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __sub__(self, other: complex | float64, /) -> Self | complex128: ... # type: ignore[overload-overlap] @overload - def __sub__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __sub__(self, other: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __sub__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __rsub__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __rsub__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __rsub__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __rsub__(self, other: complex, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __rsub__(self, other: complex, /) -> Self | complex128: ... @overload - def __rsub__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __rsub__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __mul__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __mul__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] @overload - def __mul__(self, other: complex | float64 | complex128, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __mul__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __mul__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __mul__(self, other: complex | float64, /) -> Self | complex128: ... # type: ignore[overload-overlap] + @overload + def __mul__(self, other: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __mul__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __rmul__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __rmul__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __rmul__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __rmul__(self, other: complex, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __rmul__(self, other: complex, /) -> Self | complex128: ... @overload - def __rmul__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __rmul__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __truediv__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __truediv__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __truediv__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... + @overload + def __truediv__(self, other: complex | float64, /) -> Self | complex128: ... # type: ignore[overload-overlap] @overload - def __truediv__(self, other: complex | float64 | complex128, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __truediv__(self, other: longdouble | clongdouble, /) -> clongdouble: ... @overload - def __truediv__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __truediv__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __rtruediv__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __rtruediv__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] @overload - def __rtruediv__(self, other: complex, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __rtruediv__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __rtruediv__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __rtruediv__(self, other: complex, /) -> Self | complex128: ... + @overload + def __rtruediv__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __pow__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __pow__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] + @overload + def __pow__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... + @overload + def __pow__(self, other: complex | float64, /) -> Self | complex128: ... # type: ignore[overload-overlap] @overload - def __pow__(self, other: complex | float64 | complex128, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __pow__(self, other: longdouble | clongdouble, /) -> clongdouble: ... @overload - def __pow__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __pow__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... # @overload - def __rpow__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ... + def __rpow__(self, other: inexact[_NBit1] | _Complex64_co, /) -> Self: ... # type: ignore[overload-overlap] @overload - def __rpow__(self, other: complex, /) -> complexfloating[_NBit1, _NBit2] | complex128: ... + def __rpow__(self: complex64 | complex128, other: _BinOperandComplex128_co, /) -> complex128: ... @overload - def __rpow__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ... + def __rpow__(self, other: complex, /) -> Self | complex128: ... + @overload + def __rpow__(self, other: number[_NBit], /) -> complexfloating[_NBit | _NBit1, _NBit | _NBit2]: ... class complex128(complexfloating[_64Bit], complex): # type: ignore[misc] @overload @@ -4572,34 +4729,44 @@ class complex128(complexfloating[_64Bit], complex): # type: ignore[misc] def __getnewargs__(self, /) -> tuple[float, float]: ... # complex128-specific operator overrides - @overload + @overload # type: ignore[override] def __add__(self, rhs: _Complex128_co, /) -> complex128: ... @overload - def __add__(self, rhs: complexfloating[_NBit1, _NBit2], /) -> complexfloating[_NBit1 | _64Bit, _NBit2 | _64Bit]: ... + def __add__(self, rhs: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __add__(self, rhs: inexact[_NBit], /) -> complexfloating[_NBit | _64Bit]: ... # pyright: ignore[reportIncompatibleMethodOverride] # - @overload + @overload # type: ignore[override] def __sub__(self, rhs: _Complex128_co, /) -> complex128: ... @overload - def __sub__(self, rhs: complexfloating[_NBit1, _NBit2], /) -> complexfloating[_NBit1 | _64Bit, _NBit2 | _64Bit]: ... + def __sub__(self, rhs: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __sub__(self, rhs: inexact[_NBit], /) -> complexfloating[_NBit | _64Bit]: ... # pyright: ignore[reportIncompatibleMethodOverride] # - @overload + @overload # type: ignore[override] def __mul__(self, rhs: _Complex128_co, /) -> complex128: ... @overload - def __mul__(self, rhs: complexfloating[_NBit1, _NBit2], /) -> complexfloating[_NBit1 | _64Bit, _NBit2 | _64Bit]: ... + def __mul__(self, rhs: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __mul__(self, rhs: inexact[_NBit], /) -> complexfloating[_NBit | _64Bit]: ... # pyright: ignore[reportIncompatibleMethodOverride] # - @overload + @overload # type: ignore[override] def __truediv__(self, rhs: _Complex128_co, /) -> complex128: ... @overload - def __truediv__(self, rhs: complexfloating[_NBit1, _NBit2], /) -> complexfloating[_NBit1 | _64Bit, _NBit2 | _64Bit]: ... + def __truediv__(self, rhs: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __truediv__(self, rhs: inexact[_NBit], /) -> complexfloating[_NBit | _64Bit]: ... # pyright: ignore[reportIncompatibleMethodOverride] # - @overload + @overload # type: ignore[override] def __pow__(self, rhs: _Complex128_co, /) -> complex128: ... @overload - def __pow__(self, rhs: complexfloating[_NBit1, _NBit2], /) -> complexfloating[_NBit1 | _64Bit, _NBit2 | _64Bit]: ... + def __pow__(self, rhs: longdouble | clongdouble, /) -> clongdouble: ... + @overload + def __pow__(self, rhs: inexact[_NBit], /) -> complexfloating[_NBit | _64Bit]: ... # pyright: ignore[reportIncompatibleMethodOverride] # def __radd__(self, lhs: _Complex128_co, /) -> complex128: ... diff --git a/src/numpy-stubs/_typing/_callable.pyi b/src/numpy-stubs/_typing/_callable.pyi index 8935b57d..1575fdcb 100644 --- a/src/numpy-stubs/_typing/_callable.pyi +++ b/src/numpy-stubs/_typing/_callable.pyi @@ -1,315 +1,346 @@ -from typing import ( - Any, - NoReturn, - Protocol, - TypeAlias, - final, - overload, - type_check_only, -) +from typing import Any, NoReturn, Protocol, TypeAlias, overload, type_check_only from typing_extensions import TypeVar import numpy as np from . import NBitBase from ._array_like import NDArray -from ._nbit import _NBitInt +from ._nbit import _NBitLongDouble +from ._nbit_base import _8Bit, _16Bit, _32Bit, _64Bit from ._nested_sequence import _NestedSequence -from ._scalars import _BoolLike_co, _IntLike_co, _NumberLike_co +from ._scalars import _BoolLike_co, _IntLike_co -_T1 = TypeVar("_T1") +_T = TypeVar("_T") _T1_contra = TypeVar("_T1_contra", contravariant=True) _T2_contra = TypeVar("_T2_contra", contravariant=True) -_2Tuple: TypeAlias = tuple[_T1, _T1] - +_NBit = TypeVar("_NBit", bound=NBitBase) _NBit1 = TypeVar("_NBit1", bound=NBitBase) -_NBit2 = TypeVar("_NBit2", bound=NBitBase) -_IntType = TypeVar("_IntType", bound=np.integer) -_FloatType = TypeVar("_FloatType", bound=np.floating) -_NumberType = TypeVar("_NumberType", bound=np.number) -_GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=np.generic) +_RealT = TypeVar("_RealT", bound=np.integer | np.floating) +_InexactT = TypeVar("_InexactT", bound=np.inexact) +_NumberT = TypeVar("_NumberT", bound=np.number) +_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True) + +_2Tuple: TypeAlias = tuple[_T, _T] + +### @type_check_only -class _BoolOp(Protocol[_GenericType_co]): +class _BoolOp(Protocol[_ScalarT_co]): @overload - def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ... - @overload # platform dependent - def __call__(self, other: int, /) -> np.int_: ... + def __call__(self, x: _NumberT, /) -> _NumberT: ... @overload - def __call__(self, other: float, /) -> np.float64: ... + def __call__(self, x: bool | np.bool, /) -> _ScalarT_co: ... @overload - def __call__(self, other: complex, /) -> np.complex128: ... + def __call__(self, x: int, /) -> _ScalarT_co | np.int_: ... @overload - def __call__(self, other: _NumberType, /) -> _NumberType: ... - -@type_check_only -class _BoolBitOp(Protocol[_GenericType_co]): - @overload - def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ... - @overload # platform dependent - def __call__(self, other: int, /) -> np.int_: ... + def __call__(self, x: int | float, /) -> _ScalarT_co | np.int_ | np.float64: ... @overload - def __call__(self, other: _IntType, /) -> _IntType: ... + def __call__(self, x: int | float | complex, /) -> _ScalarT_co | np.int_ | np.float64 | np.complex128: ... @type_check_only class _BoolSub(Protocol): - # Note that `other: bool` is absent here + # Note that `x: bool` is absent here + @overload + def __call__(self, x: _NumberT, /) -> _NumberT: ... @overload - def __call__(self, other: bool, /) -> NoReturn: ... - @overload # platform dependent - def __call__(self, other: int, /) -> np.int_: ... + def __call__(self, x: bool, /) -> NoReturn: ... @overload - def __call__(self, other: float, /) -> np.float64: ... + def __call__(self, x: int, /) -> np.int_: ... @overload - def __call__(self, other: complex, /) -> np.complex128: ... + def __call__(self, x: int | float, /) -> np.int_ | np.float64: ... @overload - def __call__(self, other: _NumberType, /) -> _NumberType: ... + def __call__(self, x: int | float | complex, /) -> np.int_ | np.float64 | np.complex128: ... @type_check_only class _BoolTrueDiv(Protocol): @overload - def __call__(self, other: float | _IntLike_co, /) -> np.float64: ... + def __call__(self, x: _InexactT, /) -> _InexactT: ... @overload - def __call__(self, other: complex, /) -> np.complex128: ... + def __call__(self, x: int | float | _IntLike_co, /) -> np.float64: ... @overload - def __call__(self, other: _NumberType, /) -> _NumberType: ... + def __call__(self, x: int | float | complex, /) -> np.float64 | np.complex128: ... @type_check_only class _BoolMod(Protocol): @overload - def __call__(self, other: _BoolLike_co, /) -> np.int8: ... - @overload # platform dependent - def __call__(self, other: int, /) -> np.int_: ... + def __call__(self, x: _RealT, /) -> _RealT: ... @overload - def __call__(self, other: float, /) -> np.float64: ... + def __call__(self, x: _BoolLike_co, /) -> np.int8: ... @overload - def __call__(self, other: _IntType, /) -> _IntType: ... + def __call__(self, x: int, /) -> np.int8 | np.int_: ... @overload - def __call__(self, other: _FloatType, /) -> _FloatType: ... + def __call__(self, x: int | float, /) -> np.int8 | np.int_ | np.float64: ... @type_check_only class _BoolDivMod(Protocol): @overload - def __call__(self, other: _BoolLike_co, /) -> _2Tuple[np.int8]: ... - @overload # platform dependent - def __call__(self, other: int, /) -> _2Tuple[np.int_]: ... + def __call__(self, x: _RealT, /) -> _2Tuple[_RealT]: ... @overload - def __call__(self, other: float, /) -> _2Tuple[np.float64]: ... + def __call__(self, x: _BoolLike_co, /) -> _2Tuple[np.int8]: ... @overload - def __call__(self, other: _IntType, /) -> _2Tuple[_IntType]: ... + def __call__(self, x: int, /) -> _2Tuple[np.int8] | _2Tuple[np.int_]: ... @overload - def __call__(self, other: _FloatType, /) -> _2Tuple[_FloatType]: ... + def __call__(self, x: int | float, /) -> _2Tuple[np.int8] | _2Tuple[np.int_] | _2Tuple[np.float64]: ... + +### @type_check_only -class _IntTrueDiv(Protocol[_NBit1]): +class _SignedIntOp(Protocol[_NBit]): + @overload + def __call__(self, x: int | np.signedinteger[_NBit] | np.int8 | np.bool, /) -> np.signedinteger[_NBit]: ... + @overload + def __call__(self, x: np.int64, /) -> np.int64: ... @overload - def __call__(self, other: bool, /) -> np.floating[_NBit1]: ... + def __call__(self: _SignedIntOp[_64Bit], x: np.signedinteger, /) -> np.int64: ... @overload - def __call__(self, other: int, /) -> np.floating[_NBit1] | np.floating[_NBitInt]: ... + def __call__(self, x: np.signedinteger[_NBit1], /) -> np.signedinteger[_NBit | _NBit1]: ... @overload - def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ... + def __call__(self, x: np.float64, /) -> np.float64: ... @overload - def __call__(self, other: complex, /) -> np.complexfloating[_NBit1] | np.complex128: ... + def __call__(self, x: int | float, /) -> np.signedinteger[_NBit] | np.float64: ... @overload - def __call__(self, other: np.integer[_NBit2], /) -> np.floating[_NBit1] | np.floating[_NBit2]: ... + def __call__(self, x: np.complex128, /) -> np.complex128: ... + @overload + def __call__(self, x: int | float | complex, /) -> np.signedinteger[_NBit] | np.float64 | np.complex128: ... + +### @type_check_only -class _UnsignedIntOp(Protocol[_NBit1]): - # NOTE: `uint64 + np.signedinteger -> np.float64` +class _UnsignedIntOp(Protocol[_NBit]): @overload - def __call__(self, other: int, /) -> np.unsignedinteger[_NBit1]: ... + def __call__(self, x: int | np.unsignedinteger[_NBit] | np.uint8 | np.bool, /) -> np.unsignedinteger[_NBit]: ... @overload - def __call__(self, other: float, /) -> np.float64: ... + def __call__(self, x: np.uint64, /) -> np.uint64: ... @overload - def __call__(self, other: complex, /) -> np.complex128: ... + def __call__(self: _UnsignedIntOp[_64Bit], x: np.unsignedinteger, /) -> np.uint64: ... @overload - def __call__(self, other: np.unsignedinteger[_NBit2], /) -> np.unsignedinteger[_NBit1] | np.unsignedinteger[_NBit2]: ... + def __call__(self, x: np.unsignedinteger[_NBit1], /) -> np.unsignedinteger[_NBit | _NBit1]: ... @overload - def __call__(self, other: np.signedinteger, /) -> Any: ... - -@type_check_only -class _UnsignedIntBitOp(Protocol[_NBit1]): + def __call__(self: _UnsignedIntOp[_8Bit] | _UnsignedIntOp[_16Bit], x: np.int32, /) -> np.int32: ... @overload - def __call__(self, other: bool, /) -> np.unsignedinteger[_NBit1]: ... + def __call__(self: _UnsignedIntOp[_8Bit] | _UnsignedIntOp[_16Bit], x: np.int64, /) -> np.int64: ... @overload - def __call__(self, other: int, /) -> np.signedinteger[Any]: ... + def __call__(self: _UnsignedIntOp[_8Bit], x: np.int8 | np.int16, /) -> np.int16: ... @overload - def __call__(self, other: np.signedinteger[Any], /) -> np.signedinteger[Any]: ... + def __call__(self: _UnsignedIntOp[_16Bit], x: np.int8 | np.int16, /) -> np.int32: ... @overload - def __call__(self, other: np.unsignedinteger[_NBit2], /) -> np.unsignedinteger[_NBit1] | np.unsignedinteger[_NBit2]: ... - -@type_check_only -class _UnsignedIntMod(Protocol[_NBit1]): + def __call__(self: _UnsignedIntOp[_32Bit], x: np.signedinteger, /) -> np.int64: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: bool, /) -> np.unsignedinteger[_NBit1]: ... + def __call__(self: _UnsignedIntOp[_64Bit], x: np.signedinteger, /) -> np.float64: ... @overload - def __call__(self, other: int | np.signedinteger[Any], /) -> Any: ... + def __call__(self, x: np.signedinteger, /) -> Any: ... @overload - def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ... + def __call__(self, x: np.float64, /) -> np.float64: ... @overload - def __call__(self, other: np.unsignedinteger[_NBit2], /) -> np.unsignedinteger[_NBit1] | np.unsignedinteger[_NBit2]: ... + def __call__(self, x: int | float, /) -> np.unsignedinteger[_NBit] | np.float64: ... + @overload + def __call__(self, x: np.complex128, /) -> np.complex128: ... + @overload + def __call__(self, x: int | float | complex, /) -> np.unsignedinteger[_NBit] | np.float64 | np.complex128: ... +# same as _UnsignedIntOp, minus the last (complex) overloads @type_check_only -class _UnsignedIntDivMod(Protocol[_NBit1]): +class _UnsignedIntMod(Protocol[_NBit]): @overload - def __call__(self, other: bool, /) -> _2Tuple[np.signedinteger[_NBit1]]: ... + def __call__(self, x: int | np.unsignedinteger[_NBit] | np.uint8 | np.bool, /) -> np.unsignedinteger[_NBit]: ... @overload - def __call__(self, other: int | np.signedinteger[Any], /) -> _2Tuple[Any]: ... + def __call__(self, x: np.unsignedinteger[_NBit1], /) -> np.unsignedinteger[_NBit | _NBit1]: ... @overload - def __call__(self, other: float, /) -> _2Tuple[np.floating[_NBit1]] | _2Tuple[np.float64]: ... + def __call__(self: _UnsignedIntMod[_8Bit] | _UnsignedIntMod[_16Bit], x: np.int32, /) -> np.int32: ... @overload - def __call__( - self, other: np.unsignedinteger[_NBit2], / - ) -> _2Tuple[np.unsignedinteger[_NBit1]] | _2Tuple[np.unsignedinteger[_NBit2]]: ... - -@type_check_only -class _SignedIntOp(Protocol[_NBit1]): + def __call__(self: _UnsignedIntMod[_8Bit] | _UnsignedIntMod[_16Bit], x: np.int64, /) -> np.int64: ... @overload - def __call__(self, other: int, /) -> np.signedinteger[_NBit1]: ... + def __call__(self: _UnsignedIntMod[_8Bit], x: np.int8 | np.int16, /) -> np.int16: ... @overload - def __call__(self, other: float, /) -> np.float64: ... + def __call__(self: _UnsignedIntMod[_16Bit], x: np.int8 | np.int16, /) -> np.int32: ... @overload - def __call__(self, other: complex, /) -> np.complex128: ... + def __call__(self: _UnsignedIntMod[_32Bit], x: np.signedinteger, /) -> np.int64: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: np.signedinteger[_NBit2], /) -> np.signedinteger[_NBit1] | np.signedinteger[_NBit2]: ... - -@type_check_only -class _SignedIntBitOp(Protocol[_NBit1]): + def __call__(self: _UnsignedIntMod[_64Bit], x: np.signedinteger, /) -> np.float64: ... @overload - def __call__(self, other: bool, /) -> np.signedinteger[_NBit1]: ... + def __call__(self, x: np.signedinteger, /) -> np.signedinteger | np.float64: ... @overload - def __call__(self, other: int, /) -> np.signedinteger[_NBit1] | np.int_: ... + def __call__(self, x: np.float64, /) -> np.float64: ... @overload - def __call__(self, other: np.signedinteger[_NBit2], /) -> np.signedinteger[_NBit1] | np.signedinteger[_NBit2]: ... + def __call__(self, x: int | float, /) -> np.unsignedinteger[_NBit] | np.float64: ... +# keep in sync with _UnsignedIntMod @type_check_only -class _SignedIntMod(Protocol[_NBit1]): +class _UnsignedIntDivMod(Protocol[_NBit]): + @overload + def __call__(self, x: int | np.unsignedinteger[_NBit] | np.uint8 | np.bool, /) -> _2Tuple[np.unsignedinteger[_NBit]]: ... + @overload + def __call__(self, x: np.unsignedinteger[_NBit1], /) -> _2Tuple[np.unsignedinteger[_NBit | _NBit1]]: ... @overload - def __call__(self, other: bool, /) -> np.signedinteger[_NBit1]: ... + def __call__(self: _UnsignedIntDivMod[_8Bit] | _UnsignedIntDivMod[_16Bit], x: np.int32, /) -> _2Tuple[np.int32]: ... @overload - def __call__(self, other: int, /) -> np.signedinteger[_NBit1] | np.int_: ... + def __call__(self: _UnsignedIntDivMod[_8Bit] | _UnsignedIntDivMod[_16Bit], x: np.int64, /) -> _2Tuple[np.int64]: ... @overload - def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ... + def __call__(self: _UnsignedIntDivMod[_8Bit], x: np.int8 | np.int16, /) -> _2Tuple[np.int16]: ... @overload - def __call__(self, other: np.signedinteger[_NBit2], /) -> np.signedinteger[_NBit1] | np.signedinteger[_NBit2]: ... + def __call__(self: _UnsignedIntDivMod[_16Bit], x: np.int8 | np.int16, /) -> _2Tuple[np.int32]: ... + @overload + def __call__(self: _UnsignedIntDivMod[_32Bit], x: np.signedinteger, /) -> _2Tuple[np.int64]: ... # type: ignore[overload-overlap] + @overload + def __call__(self: _UnsignedIntDivMod[_64Bit], x: np.signedinteger, /) -> _2Tuple[np.float64]: ... + @overload + def __call__(self, x: np.signedinteger, /) -> _2Tuple[np.signedinteger] | _2Tuple[np.float64]: ... + @overload + def __call__(self, x: np.float64, /) -> _2Tuple[np.float64]: ... + @overload + def __call__(self, x: int | float, /) -> _2Tuple[np.unsignedinteger[_NBit]] | _2Tuple[np.float64]: ... @type_check_only -class _SignedIntDivMod(Protocol[_NBit1]): +class _UnsignedIntBitOp(Protocol[_NBit]): + @overload + def __call__(self, x: int | np.unsignedinteger[_NBit] | np.uint8 | np.bool, /) -> np.unsignedinteger[_NBit]: ... @overload - def __call__(self, other: bool, /) -> _2Tuple[np.signedinteger[_NBit1]]: ... + def __call__(self, x: np.unsignedinteger[_NBit1], /) -> np.unsignedinteger[_NBit | _NBit1]: ... @overload - def __call__(self, other: int, /) -> _2Tuple[np.signedinteger[_NBit1]] | _2Tuple[np.int_]: ... + def __call__(self: _UnsignedIntBitOp[_8Bit], x: np.int8 | np.int16, /) -> np.int16: ... @overload - def __call__(self, other: float, /) -> _2Tuple[np.floating[_NBit1]] | _2Tuple[np.float64]: ... + def __call__(self: _UnsignedIntBitOp[_8Bit], x: np.int32, /) -> np.int32: ... + @overload + def __call__(self: _UnsignedIntBitOp[_16Bit], x: np.int8 | np.int16 | np.int32, /) -> np.int32: ... + @overload + def __call__(self: _UnsignedIntBitOp[_32Bit], x: np.signedinteger, /) -> np.int64: ... + @overload + def __call__(self: _UnsignedIntBitOp[_8Bit] | _UnsignedIntBitOp[_16Bit], x: np.int64, /) -> np.int64: ... @overload def __call__( - self, other: np.signedinteger[_NBit2], / - ) -> _2Tuple[np.signedinteger[_NBit1]] | _2Tuple[np.signedinteger[_NBit2]]: ... + self: _UnsignedIntBitOp[_8Bit] | _UnsignedIntBitOp[_16Bit] | _UnsignedIntBitOp[_32Bit], + x: np.signedinteger, + /, + ) -> np.signedinteger: ... + +### @type_check_only -class _FloatOp(Protocol[_NBit1]): +class _FloatOp(Protocol[_NBit]): + @overload + def __call__(self, x: np.bool | np.uint8 | int, /) -> np.floating[_NBit]: ... # type: ignore[overload-overlap] + @overload + def __call__(self: _FloatOp[_16Bit] | _FloatOp[_32Bit], x: np.uint16 | np.int32 | np.float32, /) -> np.float32: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: int, /) -> np.floating[_NBit1]: ... + def __call__( + self: _FloatOp[_16Bit] | _FloatOp[_32Bit], + x: np.uint32 | np.uint64 | np.uint | np.int64 | np.float64, + /, + ) -> np.float64: ... + @overload + def __call__(self: _FloatOp[_16Bit] | _FloatOp[_32Bit], x: np.complex64, /) -> np.complex64: ... # type: ignore[overload-overlap] + @overload + def __call__(self: _FloatOp[_16Bit] | _FloatOp[_32Bit], x: np.complex128, /) -> np.complex128: ... + @overload + def __call__(self: _FloatOp[_NBitLongDouble], x: np.integer | np.floating, /) -> np.longdouble: ... + @overload + def __call__(self, x: np.longdouble, /) -> np.longdouble: ... + @overload + def __call__(self: _FloatOp[_NBitLongDouble], x: np.complexfloating, /) -> np.clongdouble: ... @overload - def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ... + def __call__(self, x: np.signedinteger[_NBit1] | np.floating[_NBit1], /) -> np.floating[_NBit | _NBit1]: ... @overload - def __call__(self, other: complex, /) -> np.complexfloating[_NBit1] | np.complex128: ... + def __call__(self, x: int | float, /) -> np.floating[_NBit]: ... @overload - def __call__(self, other: np.integer[_NBit2] | np.floating[_NBit2], /) -> np.floating[_NBit1] | np.floating[_NBit2]: ... + def __call__(self, x: int | float | complex, /) -> np.floating[_NBit] | np.complexfloating[_NBit]: ... @type_check_only -class _FloatMod(Protocol[_NBit1]): +class _FloatMod(Protocol[_NBit]): @overload - def __call__(self, other: bool, /) -> np.floating[_NBit1]: ... + def __call__(self, x: np.bool | np.uint8 | int | float, /) -> np.floating[_NBit]: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: int, /) -> np.floating[_NBit1] | np.floating[_NBitInt]: ... + def __call__(self: _FloatMod[_16Bit] | _FloatMod[_32Bit], x: np.uint16 | np.int32 | np.float32, /) -> np.float32: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ... + def __call__( + self: _FloatMod[_16Bit] | _FloatMod[_32Bit], + x: np.uint32 | np.uint64 | np.uint | np.int64 | np.float64, + /, + ) -> np.float64: ... @overload - def __call__(self, other: np.integer[_NBit2] | np.floating[_NBit2], /) -> np.floating[_NBit1] | np.floating[_NBit2]: ... - -class _FloatDivMod(Protocol[_NBit1]): + def __call__(self: _FloatMod[_NBitLongDouble], x: np.integer | np.floating, /) -> np.longdouble: ... @overload - def __call__(self, other: bool, /) -> _2Tuple[np.floating[_NBit1]]: ... + def __call__(self, x: np.signedinteger[_NBit1] | np.floating[_NBit1], /) -> np.floating[_NBit | _NBit1]: ... + +class _FloatDivMod(Protocol[_NBit]): @overload - def __call__(self, other: int, /) -> _2Tuple[np.floating[_NBit1]] | _2Tuple[np.floating[_NBitInt]]: ... + def __call__(self, x: np.bool | np.uint8 | int | float, /) -> _2Tuple[np.floating[_NBit]]: ... # type: ignore[overload-overlap] @overload - def __call__(self, other: float, /) -> _2Tuple[np.floating[_NBit1]] | _2Tuple[np.float64]: ... + def __call__( # type: ignore[overload-overlap] + self: _FloatDivMod[_16Bit] | _FloatDivMod[_32Bit], + x: np.uint16 | np.int32 | np.float32, + /, + ) -> _2Tuple[np.float32]: ... @overload def __call__( - self, other: np.integer[_NBit2] | np.floating[_NBit2], / - ) -> _2Tuple[np.floating[_NBit1]] | _2Tuple[np.floating[_NBit2]]: ... + self: _FloatDivMod[_16Bit] | _FloatDivMod[_32Bit], + x: np.uint32 | np.uint64 | np.uint | np.int64 | np.float64, + /, + ) -> _2Tuple[np.float64]: ... + @overload + def __call__(self: _FloatDivMod[_NBitLongDouble], x: np.integer | np.floating, /) -> _2Tuple[np.longdouble]: ... + @overload + def __call__(self, x: np.signedinteger[_NBit1] | np.floating[_NBit1], /) -> _2Tuple[np.floating[_NBit | _NBit1]]: ... -@type_check_only -class _NumberOp(Protocol): - def __call__(self, other: _NumberLike_co, /) -> Any: ... +### -@final @type_check_only -class _SupportsLT(Protocol): - def __lt__(self, other: Any, /) -> Any: ... +class _CanLT(Protocol): + def __lt__(self, x: Any, /) -> Any: ... -@final @type_check_only -class _SupportsLE(Protocol): - def __le__(self, other: Any, /) -> Any: ... +class _CanLE(Protocol): + def __le__(self, x: Any, /) -> Any: ... -@final @type_check_only -class _SupportsGT(Protocol): - def __gt__(self, other: Any, /) -> Any: ... +class _CanGT(Protocol): + def __gt__(self, x: Any, /) -> Any: ... -@final @type_check_only -class _SupportsGE(Protocol): - def __ge__(self, other: Any, /) -> Any: ... +class _CanGE(Protocol): + def __ge__(self, x: Any, /) -> Any: ... -@final @type_check_only class _ComparisonOpLT(Protocol[_T1_contra, _T2_contra]): @overload - def __call__(self, other: _T1_contra, /) -> np.bool: ... + def __call__(self, x: _T1_contra, /) -> np.bool: ... @overload - def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + def __call__(self, x: _T2_contra, /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _NestedSequence[_SupportsGT], /) -> NDArray[np.bool]: ... + def __call__(self, x: _NestedSequence[_CanGT], /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _SupportsGT, /) -> np.bool: ... + def __call__(self, x: _CanGT, /) -> np.bool: ... -@final @type_check_only class _ComparisonOpLE(Protocol[_T1_contra, _T2_contra]): @overload - def __call__(self, other: _T1_contra, /) -> np.bool: ... + def __call__(self, x: _T1_contra, /) -> np.bool: ... @overload - def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + def __call__(self, x: _T2_contra, /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _NestedSequence[_SupportsGE], /) -> NDArray[np.bool]: ... + def __call__(self, x: _NestedSequence[_CanGE], /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _SupportsGE, /) -> np.bool: ... + def __call__(self, x: _CanGE, /) -> np.bool: ... -@final @type_check_only class _ComparisonOpGT(Protocol[_T1_contra, _T2_contra]): @overload - def __call__(self, other: _T1_contra, /) -> np.bool: ... + def __call__(self, x: _T1_contra, /) -> np.bool: ... @overload - def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + def __call__(self, x: _T2_contra, /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _NestedSequence[_SupportsLT], /) -> NDArray[np.bool]: ... + def __call__(self, x: _NestedSequence[_CanLT], /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _SupportsLT, /) -> np.bool: ... + def __call__(self, x: _CanLT, /) -> np.bool: ... -@final @type_check_only class _ComparisonOpGE(Protocol[_T1_contra, _T2_contra]): @overload - def __call__(self, other: _T1_contra, /) -> np.bool: ... + def __call__(self, x: _T1_contra, /) -> np.bool: ... @overload - def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + def __call__(self, x: _T2_contra, /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _NestedSequence[_SupportsGT], /) -> NDArray[np.bool]: ... + def __call__(self, x: _NestedSequence[_CanGT], /) -> NDArray[np.bool]: ... @overload - def __call__(self, other: _SupportsGT, /) -> np.bool: ... + def __call__(self, x: _CanGT, /) -> np.bool: ... diff --git a/src/numpy-stubs/_typing/_ufunc.pyi b/src/numpy-stubs/_typing/_ufunc.pyi index 902b920f..6f8af49e 100644 --- a/src/numpy-stubs/_typing/_ufunc.pyi +++ b/src/numpy-stubs/_typing/_ufunc.pyi @@ -70,11 +70,11 @@ class _UFunc3Kwargs(TypedDict, total=False): # pyright: reportIncompatibleMethodOverride=false @type_check_only -class _UFunc_Nin1_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] +class _UFunc_Nin1_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def __name__(self) -> _NameT_co: ... @property - def __qualname__(self) -> _NameT_co: ... + def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def ntypes(self) -> _NTypesT_co: ... @property @@ -136,11 +136,11 @@ class _UFunc_Nin1_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co] def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _UFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] +class _UFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def __name__(self) -> _NameT_co: ... @property - def __qualname__(self) -> _NameT_co: ... + def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def ntypes(self) -> _NTypesT_co: ... @property @@ -291,11 +291,11 @@ class _UFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co] ) -> npt.NDArray[Any] | Any: ... @type_check_only -class _UFunc_Nin1_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] +class _UFunc_Nin1_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def __name__(self) -> _NameT_co: ... @property - def __qualname__(self) -> _NameT_co: ... + def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def ntypes(self) -> _NTypesT_co: ... @property @@ -362,11 +362,11 @@ class _UFunc_Nin1_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co] def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _UFunc_Nin2_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] +class _UFunc_Nin2_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def __name__(self) -> _NameT_co: ... @property - def __qualname__(self) -> _NameT_co: ... + def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def ntypes(self) -> _NTypesT_co: ... @property @@ -419,11 +419,11 @@ class _UFunc_Nin2_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co] def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _GUFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co, _SignatureT_co]): # type: ignore[misc] +class _GUFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co, _SignatureT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def __name__(self) -> _NameT_co: ... @property - def __qualname__(self) -> _NameT_co: ... + def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def ntypes(self) -> _NTypesT_co: ... @property @@ -511,7 +511,7 @@ class _PyFunc_Kwargs_Nargs4P(TypedDict, total=False): signature: str | _4PTuple[DTypeLike] @type_check_only -class _PyFunc_Nin1_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] +class _PyFunc_Nin1_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def identity(self) -> _IdentityT_co: ... @property @@ -563,7 +563,7 @@ class _PyFunc_Nin1_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: i def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _PyFunc_Nin2_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] +class _PyFunc_Nin2_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def identity(self) -> _IdentityT_co: ... @property @@ -792,7 +792,7 @@ class _PyFunc_Nin2_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: i ) -> Any: ... @type_check_only -class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co, _NInT_co]): # type: ignore[misc] +class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co, _NInT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def identity(self) -> _IdentityT_co: ... @property @@ -854,7 +854,7 @@ class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co, _NInT_co]): def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _PyFunc_Nin1P_Nout2P(np.ufunc, Generic[_OutT_co, _IdentityT_co, _NInT_co, _NOutT_co]): # type: ignore[misc] +class _PyFunc_Nin1P_Nout2P(np.ufunc, Generic[_OutT_co, _IdentityT_co, _NInT_co, _NOutT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] @property def identity(self) -> _IdentityT_co: ... @property diff --git a/test/runtime/accept/mod.py b/test/runtime/accept/mod.py index 0b3e97a8..b2f2099a 100644 --- a/test/runtime/accept/mod.py +++ b/test/runtime/accept/mod.py @@ -42,9 +42,9 @@ b_ % f8 b_ % AR -divmod(b_, b) divmod(b_, b_) # workarounds for https://github.com/microsoft/pyright/issues/9663 +b_.__divmod__(b) b_.__divmod__(i) b_.__divmod__(f) b_.__divmod__(i8) @@ -87,9 +87,9 @@ # workarounds for https://github.com/microsoft/pyright/issues/9663 i8.__divmod__(i) i8.__divmod__(f) +i8.__divmod__(i4) divmod(i8, i8) divmod(i8, f8) -divmod(i8, i4) divmod(i8, f4) divmod(i4, i4) divmod(i4, f4) @@ -111,9 +111,9 @@ divmod(f, i8) divmod(i8, i8) divmod(f8, i8) -divmod(i4, i8) divmod(i4, i4) # workarounds for https://github.com/microsoft/pyright/issues/9663 +i4.__divmod__(i8) f4.__divmod__(i8) f4.__divmod__(i4) AR.__divmod__(i8) diff --git a/test/static/accept/arithmetic.pyi b/test/static/accept/arithmetic.pyi index 96d4da0e..291f0249 100644 --- a/test/static/accept/arithmetic.pyi +++ b/test/static/accept/arithmetic.pyi @@ -4,28 +4,26 @@ from typing_extensions import assert_type import numpy as np import numpy.typing as npt -from numpy._typing import _32Bit, _64Bit, _128Bit +from numpy._typing import _64Bit b: bool -c: complex -f: float i: int +f: float +c: complex -c16: np.complex128 -c8: np.complex64 - -# Can't directly import `np.float128` as it is not available on all platforms -f16: np.floating[_128Bit] -f8: np.float64 -f4: np.float32 +b_: np.bool -i8: np.int64 i4: np.int32 - -u8: np.uint64 u4: np.uint32 +i8: np.int64 +u8: np.uint64 -b_: np.bool +f4: np.float32 +f8: np.float64 +f16: np.longdouble + +c8: np.complex64 +c16: np.complex128 M8: np.datetime64 M8_none: np.datetime64[None] @@ -49,7 +47,7 @@ AR_c: npt.NDArray[np.complex128] AR_m: npt.NDArray[np.timedelta64] AR_M: npt.NDArray[np.datetime64] AR_O: npt.NDArray[np.object_] -AR_number: npt.NDArray[np.number[Any]] +AR_number: npt.NDArray[np.number] AR_Any: npt.NDArray[Any] AR_LIKE_b: list[bool] @@ -63,53 +61,53 @@ AR_LIKE_O: list[np.object_] # Array subtraction -assert_type(AR_number - AR_number, npt.NDArray[np.number[Any]]) +assert_type(AR_number - AR_number, npt.NDArray[np.number]) assert_type(AR_b - AR_LIKE_u, npt.NDArray[np.uint32]) -assert_type(AR_b - AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_b - AR_LIKE_f, npt.NDArray[np.floating[Any]]) -assert_type(AR_b - AR_LIKE_c, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_b - AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_b - AR_LIKE_f, npt.NDArray[np.floating]) +assert_type(AR_b - AR_LIKE_c, npt.NDArray[np.complexfloating]) assert_type(AR_b - AR_LIKE_m, npt.NDArray[np.timedelta64]) assert_type(AR_b - AR_LIKE_O, Any) assert_type(AR_LIKE_u - AR_b, npt.NDArray[np.uint32]) -assert_type(AR_LIKE_i - AR_b, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f - AR_b, npt.NDArray[np.floating[Any]]) -assert_type(AR_LIKE_c - AR_b, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_LIKE_i - AR_b, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f - AR_b, npt.NDArray[np.floating]) +assert_type(AR_LIKE_c - AR_b, npt.NDArray[np.complexfloating]) assert_type(AR_LIKE_m - AR_b, npt.NDArray[np.timedelta64]) assert_type(AR_LIKE_M - AR_b, npt.NDArray[np.datetime64]) assert_type(AR_LIKE_O - AR_b, Any) assert_type(AR_u - AR_LIKE_b, npt.NDArray[np.uint32]) -assert_type(AR_u - AR_LIKE_u, npt.NDArray[np.unsignedinteger[Any]]) -assert_type(AR_u - AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_u - AR_LIKE_f, npt.NDArray[np.floating[Any]]) -assert_type(AR_u - AR_LIKE_c, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_u - AR_LIKE_u, npt.NDArray[np.unsignedinteger]) +assert_type(AR_u - AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_u - AR_LIKE_f, npt.NDArray[np.floating]) +assert_type(AR_u - AR_LIKE_c, npt.NDArray[np.complexfloating]) assert_type(AR_u - AR_LIKE_m, npt.NDArray[np.timedelta64]) assert_type(AR_u - AR_LIKE_O, Any) assert_type(AR_LIKE_b - AR_u, npt.NDArray[np.uint32]) -assert_type(AR_LIKE_u - AR_u, npt.NDArray[np.unsignedinteger[Any]]) -assert_type(AR_LIKE_i - AR_u, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f - AR_u, npt.NDArray[np.floating[Any]]) -assert_type(AR_LIKE_c - AR_u, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_LIKE_u - AR_u, npt.NDArray[np.unsignedinteger]) +assert_type(AR_LIKE_i - AR_u, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f - AR_u, npt.NDArray[np.floating]) +assert_type(AR_LIKE_c - AR_u, npt.NDArray[np.complexfloating]) assert_type(AR_LIKE_m - AR_u, npt.NDArray[np.timedelta64]) assert_type(AR_LIKE_M - AR_u, npt.NDArray[np.datetime64]) assert_type(AR_LIKE_O - AR_u, Any) assert_type(AR_i - AR_LIKE_b, npt.NDArray[np.int64]) -assert_type(AR_i - AR_LIKE_u, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_i - AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_i - AR_LIKE_f, npt.NDArray[np.floating[Any]]) -assert_type(AR_i - AR_LIKE_c, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_i - AR_LIKE_u, npt.NDArray[np.signedinteger]) +assert_type(AR_i - AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_i - AR_LIKE_f, npt.NDArray[np.floating]) +assert_type(AR_i - AR_LIKE_c, npt.NDArray[np.complexfloating]) assert_type(AR_i - AR_LIKE_m, npt.NDArray[np.timedelta64]) assert_type(AR_i - AR_LIKE_O, Any) assert_type(AR_LIKE_b - AR_i, npt.NDArray[np.int64]) -assert_type(AR_LIKE_u - AR_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_i - AR_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f - AR_i, npt.NDArray[np.floating[Any]]) -assert_type(AR_LIKE_c - AR_i, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_LIKE_u - AR_i, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_i - AR_i, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f - AR_i, npt.NDArray[np.floating]) +assert_type(AR_LIKE_c - AR_i, npt.NDArray[np.complexfloating]) assert_type(AR_LIKE_m - AR_i, npt.NDArray[np.timedelta64]) assert_type(AR_LIKE_M - AR_i, npt.NDArray[np.datetime64]) assert_type(AR_LIKE_O - AR_i, Any) @@ -118,14 +116,14 @@ assert_type(AR_f - AR_LIKE_b, npt.NDArray[np.float64]) assert_type(AR_f - AR_LIKE_u, npt.NDArray[np.float64]) assert_type(AR_f - AR_LIKE_i, npt.NDArray[np.float64]) assert_type(AR_f - AR_LIKE_f, npt.NDArray[np.float64]) -assert_type(AR_f - AR_LIKE_c, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_f - AR_LIKE_c, npt.NDArray[np.complexfloating]) assert_type(AR_f - AR_LIKE_O, Any) assert_type(AR_LIKE_b - AR_f, npt.NDArray[np.float64]) assert_type(AR_LIKE_u - AR_f, npt.NDArray[np.float64]) assert_type(AR_LIKE_i - AR_f, npt.NDArray[np.float64]) assert_type(AR_LIKE_f - AR_f, npt.NDArray[np.float64]) -assert_type(AR_LIKE_c - AR_f, npt.NDArray[np.complexfloating[Any, Any]]) +assert_type(AR_LIKE_c - AR_f, npt.NDArray[np.complexfloating]) assert_type(AR_LIKE_O - AR_f, Any) assert_type(AR_c - AR_LIKE_b, npt.NDArray[np.complex128]) @@ -187,39 +185,39 @@ assert_type(AR_LIKE_O - AR_O, Any) assert_type(AR_b // AR_LIKE_b, npt.NDArray[np.int8]) assert_type(AR_b // AR_LIKE_u, npt.NDArray[np.uint32]) -assert_type(AR_b // AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_b // AR_LIKE_f, npt.NDArray[np.floating[Any]]) +assert_type(AR_b // AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_b // AR_LIKE_f, npt.NDArray[np.floating]) assert_type(AR_b // AR_LIKE_O, Any) assert_type(AR_LIKE_b // AR_b, npt.NDArray[np.int8]) assert_type(AR_LIKE_u // AR_b, npt.NDArray[np.uint32]) -assert_type(AR_LIKE_i // AR_b, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f // AR_b, npt.NDArray[np.floating[Any]]) +assert_type(AR_LIKE_i // AR_b, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f // AR_b, npt.NDArray[np.floating]) assert_type(AR_LIKE_O // AR_b, Any) assert_type(AR_u // AR_LIKE_b, npt.NDArray[np.uint32]) -assert_type(AR_u // AR_LIKE_u, npt.NDArray[np.unsignedinteger[Any]]) -assert_type(AR_u // AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_u // AR_LIKE_f, npt.NDArray[np.floating[Any]]) +assert_type(AR_u // AR_LIKE_u, npt.NDArray[np.unsignedinteger]) +assert_type(AR_u // AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_u // AR_LIKE_f, npt.NDArray[np.floating]) assert_type(AR_u // AR_LIKE_O, Any) assert_type(AR_LIKE_b // AR_u, npt.NDArray[np.uint32]) -assert_type(AR_LIKE_u // AR_u, npt.NDArray[np.unsignedinteger[Any]]) -assert_type(AR_LIKE_i // AR_u, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f // AR_u, npt.NDArray[np.floating[Any]]) +assert_type(AR_LIKE_u // AR_u, npt.NDArray[np.unsignedinteger]) +assert_type(AR_LIKE_i // AR_u, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f // AR_u, npt.NDArray[np.floating]) assert_type(AR_LIKE_m // AR_u, npt.NDArray[np.timedelta64]) assert_type(AR_LIKE_O // AR_u, Any) assert_type(AR_i // AR_LIKE_b, npt.NDArray[np.int64]) -assert_type(AR_i // AR_LIKE_u, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_i // AR_LIKE_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_i // AR_LIKE_f, npt.NDArray[np.floating[Any]]) +assert_type(AR_i // AR_LIKE_u, npt.NDArray[np.signedinteger]) +assert_type(AR_i // AR_LIKE_i, npt.NDArray[np.signedinteger]) +assert_type(AR_i // AR_LIKE_f, npt.NDArray[np.floating]) assert_type(AR_i // AR_LIKE_O, Any) assert_type(AR_LIKE_b // AR_i, npt.NDArray[np.int64]) -assert_type(AR_LIKE_u // AR_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_i // AR_i, npt.NDArray[np.signedinteger[Any]]) -assert_type(AR_LIKE_f // AR_i, npt.NDArray[np.floating[Any]]) +assert_type(AR_LIKE_u // AR_i, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_i // AR_i, npt.NDArray[np.signedinteger]) +assert_type(AR_LIKE_f // AR_i, npt.NDArray[np.floating]) assert_type(AR_LIKE_m // AR_i, npt.NDArray[np.timedelta64]) assert_type(AR_LIKE_O // AR_i, Any) @@ -263,7 +261,7 @@ assert_type(AR_LIKE_O // AR_O, Any) # unary ops -assert_type(-f16, np.floating[_128Bit]) +assert_type(-f16, np.longdouble) assert_type(-c16, np.complex128) assert_type(-c8, np.complex64) assert_type(-f8, np.float64) @@ -278,7 +276,7 @@ assert_type(-m8_int, np.timedelta64[int]) assert_type(-m8_delta, np.timedelta64[dt.timedelta]) assert_type(-AR_f, npt.NDArray[np.float64]) -assert_type(+f16, np.floating[_128Bit]) +assert_type(+f16, np.longdouble) assert_type(+c16, np.complex128) assert_type(+c8, np.complex64) assert_type(+f8, np.float64) @@ -292,7 +290,7 @@ assert_type(+m8_int, np.timedelta64[int]) assert_type(+m8_delta, np.timedelta64[dt.timedelta]) assert_type(+AR_f, npt.NDArray[np.float64]) -assert_type(abs(f16), np.floating[_128Bit]) +assert_type(abs(f16), np.longdouble) assert_type(abs(c16), np.float64) assert_type(abs(c8), np.float32) assert_type(abs(f8), np.float64) @@ -366,38 +364,40 @@ assert_type(m8_delta.__divmod__(delta), tuple[int, dt.timedelta]) # boolean assert_type(b_ / b, np.float64) -assert_type(b_ / b_, np.float64) assert_type(b_ / i, np.float64) -assert_type(b_ / i8, np.float64) +assert_type(b_ / f, np.float64) +assert_type(b_ / c, np.float64 | np.complex128) + +assert_type(b_ / b_, np.float64) assert_type(b_ / i4, np.float64) -assert_type(b_ / u8, np.float64) assert_type(b_ / u4, np.float64) -assert_type(b_ / f, np.float64) -assert_type(b_ / f16, np.floating[_128Bit]) -assert_type(b_ / f8, np.float64) +assert_type(b_ / i8, np.float64) +assert_type(b_ / u8, np.float64) assert_type(b_ / f4, np.float32) -assert_type(b_ / c, np.complex128) -assert_type(b_ / c16, np.complex128) +assert_type(b_ / f8, np.float64) +assert_type(b_ / f16, np.longdouble) assert_type(b_ / c8, np.complex64) +assert_type(b_ / c16, np.complex128) assert_type(b / b_, np.float64) -assert_type(b_ / b_, np.float64) assert_type(i / b_, np.float64) +assert_type(f / b_, np.float64) +assert_type(c / b_, np.float64 | np.complex128) + +assert_type(b_ / b_, np.float64) assert_type(i8 / b_, np.float64) assert_type(i4 / b_, np.float64) assert_type(u8 / b_, np.float64) assert_type(u4 / b_, np.float64) -assert_type(f / b_, np.float64) -assert_type(f16 / b_, np.floating[_128Bit]) +assert_type(f16 / b_, np.longdouble) assert_type(f8 / b_, np.float64) assert_type(f4 / b_, np.float32) -assert_type(c / b_, np.complex128) assert_type(c16 / b_, np.complex128) assert_type(c8 / b_, np.complex64) # Complex -assert_type(c16 + f16, np.complex128 | np.complexfloating[_128Bit, _128Bit]) +assert_type(c16 + f16, np.clongdouble) assert_type(c16 + c16, np.complex128) assert_type(c16 + f8, np.complex128) assert_type(c16 + i8, np.complex128) @@ -410,12 +410,12 @@ assert_type(c16 + c, np.complex128) assert_type(c16 + f, np.complex128) assert_type(c16 + AR_f, npt.NDArray[np.complex128]) -assert_type(f16 + c16, np.complex128 | np.complexfloating[_128Bit, _128Bit]) +assert_type(f16 + c16, np.clongdouble) assert_type(c16 + c16, np.complex128) assert_type(f8 + c16, np.complex128) assert_type(i8 + c16, np.complex128) -assert_type(c8 + c16, np.complex128 | np.complex64) -assert_type(f4 + c16, np.complex128 | np.complex64) +assert_type(c8 + c16, np.complex128) +assert_type(f4 + c16, np.complex128) assert_type(i4 + c16, np.complex128) assert_type(b_ + c16, np.complex128) assert_type(b + c16, np.complex128) @@ -424,36 +424,36 @@ assert_type(c + c16, np.complex128) # pyright: ignore[reportAssertTypeFailure] assert_type(f + c16, np.complex128) assert_type(AR_f + c16, npt.NDArray[np.complex128]) -assert_type(c8 + f16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_128Bit, _128Bit]) -assert_type(c8 + c16, np.complex64 | np.complex128) -assert_type(c8 + f8, np.complex64 | np.complex128) -assert_type(c8 + i8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit]) +assert_type(c8 + f16, np.clongdouble) +assert_type(c8 + c16, np.complex128) +assert_type(c8 + f8, np.complex128) +assert_type(c8 + i8, np.complex128) assert_type(c8 + c8, np.complex64) assert_type(c8 + f4, np.complex64) assert_type(c8 + i4, np.complex64) assert_type(c8 + b_, np.complex64) assert_type(c8 + b, np.complex64) -assert_type(c8 + c, np.complex64 | np.complex128) -assert_type(c8 + f, np.complex64 | np.complex128) +assert_type(c8 + c, np.complex128) +assert_type(c8 + f, np.complex128) assert_type(c8 + AR_f, npt.NDArray[np.complexfloating]) -assert_type(f16 + c8, np.complexfloating[_128Bit, _128Bit] | np.complex64) +assert_type(f16 + c8, np.clongdouble) assert_type(c16 + c8, np.complex128) # https://github.com/microsoft/pyright/issues/9684 -assert_type(f8 + c8, np.complexfloating[_64Bit, _64Bit]) # pyright: ignore[reportAssertTypeFailure] -assert_type(i8 + c8, np.complexfloating[_64Bit, _64Bit] | np.complex64) +assert_type(f8 + c8, np.complexfloating[_64Bit]) # pyright: ignore[reportAssertTypeFailure] +assert_type(i8 + c8, np.complex128) assert_type(c8 + c8, np.complex64) assert_type(f4 + c8, np.complex64) assert_type(i4 + c8, np.complex64) assert_type(b_ + c8, np.complex64) assert_type(b + c8, np.complex64) -assert_type(c + c8, np.complex64 | np.complex128) -assert_type(f + c8, np.complex64 | np.complex128) +assert_type(c + c8, np.complex128) +assert_type(f + c8, np.complex128) assert_type(AR_f + c8, npt.NDArray[np.complexfloating]) # Float -assert_type(f8 + f16, np.float64 | np.floating[_128Bit]) +assert_type(f8 + f16, np.longdouble) assert_type(f8 + f8, np.float64) assert_type(f8 + i8, np.float64) assert_type(f8 + f4, np.float64) @@ -464,10 +464,10 @@ assert_type(f8 + c, np.float64 | np.complex128) assert_type(f8 + f, np.float64) assert_type(f8 + AR_f, npt.NDArray[np.float64]) -assert_type(f16 + f8, np.floating[_128Bit] | np.float64) +assert_type(f16 + f8, np.longdouble) assert_type(f8 + f8, np.float64) assert_type(i8 + f8, np.float64) -assert_type(f4 + f8, np.float32 | np.float64) +assert_type(f4 + f8, np.float64) assert_type(i4 + f8, np.float64) assert_type(b_ + f8, np.float64) assert_type(b + f8, np.float64) @@ -476,91 +476,91 @@ assert_type(c + f8, np.complex128 | np.float64) # pyright: ignore[reportAssertT assert_type(f + f8, np.float64) # pyright: ignore[reportAssertTypeFailure] assert_type(AR_f + f8, npt.NDArray[np.float64]) -assert_type(f4 + f16, np.float32 | np.floating[_128Bit]) -assert_type(f4 + f8, np.float32 | np.float64) -assert_type(f4 + i8, np.float32 | np.floating[_64Bit]) +assert_type(f4 + b, np.float32) +assert_type(f4 + f, np.float32) +assert_type(f4 + c, np.float32 | np.complex64) +assert_type(f4 + f16, np.longdouble) +assert_type(f4 + f8, np.float64) +assert_type(f4 + i8, np.float64) assert_type(f4 + f4, np.float32) assert_type(f4 + i4, np.float32) assert_type(f4 + b_, np.float32) -assert_type(f4 + b, np.float32) -assert_type(f4 + c, np.complex64 | np.complex128) -assert_type(f4 + f, np.float32 | np.float64) assert_type(f4 + AR_f, npt.NDArray[np.float64]) -assert_type(f16 + f4, np.floating[_128Bit] | np.float32) +assert_type(b + f4, np.float32) +assert_type(f + f4, np.float32) +assert_type(c + f4, np.float32 | np.complex64) +assert_type(f16 + f4, np.longdouble) assert_type(f8 + f4, np.float64) -assert_type(i8 + f4, np.floating[_32Bit] | np.floating[_64Bit]) +assert_type(i8 + f4, np.float64) assert_type(f4 + f4, np.float32) assert_type(i4 + f4, np.float32) assert_type(b_ + f4, np.float32) -assert_type(b + f4, np.float32) -assert_type(c + f4, np.complex64 | np.complex128) -assert_type(f + f4, np.float64 | np.float32) assert_type(AR_f + f4, npt.NDArray[np.float64]) # Int +assert_type(i8 + b, np.int64) +assert_type(i8 + f, np.int64 | np.float64) +assert_type(i8 + c, np.int64 | np.float64 | np.complex128) assert_type(i8 + i8, np.int64) -assert_type(i8 + u8, Any) -assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(i8 + u4, Any) +assert_type(i8 + u8, np.float64) +assert_type(i8 + i4, np.int64) +assert_type(i8 + u4, np.int64) assert_type(i8 + b_, np.int64) -assert_type(i8 + b, np.int64) -assert_type(i8 + c, np.complex128) -assert_type(i8 + f, np.float64) assert_type(i8 + AR_f, npt.NDArray[np.float64]) +assert_type(u8 + b, np.uint64) +assert_type(u8 + f, np.uint64 | np.float64) +assert_type(u8 + c, np.uint64 | np.float64 | np.complex128) assert_type(u8 + u8, np.uint64) -assert_type(u8 + i4, Any) -assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) +assert_type(u8 + i4, np.float64) +assert_type(u8 + u4, np.uint64) assert_type(u8 + b_, np.uint64) -assert_type(u8 + b, np.uint64) -assert_type(u8 + c, np.complex128) -assert_type(u8 + f, np.float64) assert_type(u8 + AR_f, npt.NDArray[np.float64]) +assert_type(b + i8, np.int64) +assert_type(f + i8, np.int64 | np.float64) +assert_type(c + i8, np.int64 | np.float64 | np.complex128) assert_type(i8 + i8, np.int64) -assert_type(u8 + i8, Any) -assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(u4 + i8, Any) +assert_type(u8 + i8, np.float64) +assert_type(i4 + i8, np.int64) +assert_type(u4 + i8, np.int64) assert_type(b_ + i8, np.int64) -assert_type(b + i8, np.int64) -assert_type(c + i8, np.complex128) -assert_type(f + i8, np.float64) assert_type(AR_f + i8, npt.NDArray[np.float64]) +assert_type(b + u8, np.uint64) +assert_type(f + u8, np.uint64 | np.float64) +assert_type(c + u8, np.uint64 | np.float64 | np.complex128) assert_type(u8 + u8, np.uint64) -assert_type(i4 + u8, Any) -assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) +assert_type(i4 + u8, np.float64) +assert_type(u4 + u8, np.uint64) assert_type(b_ + u8, np.uint64) -assert_type(b + u8, np.uint64) -assert_type(c + u8, np.complex128) -assert_type(f + u8, np.float64) assert_type(AR_f + u8, npt.NDArray[np.float64]) -assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) +assert_type(i4 + i8, np.int64) assert_type(i4 + i4, np.int32) assert_type(i4 + b_, np.int32) assert_type(i4 + b, np.int32) assert_type(i4 + AR_f, npt.NDArray[np.float64]) -assert_type(u4 + i8, Any) -assert_type(u4 + i4, Any) -assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) +assert_type(u4 + i8, np.int64) +assert_type(u4 + i4, np.int64) +assert_type(u4 + u8, np.uint64) assert_type(u4 + u4, np.uint32) assert_type(u4 + b_, np.uint32) assert_type(u4 + b, np.uint32) assert_type(u4 + AR_f, npt.NDArray[np.float64]) -assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) +assert_type(i8 + i4, np.int64) assert_type(i4 + i4, np.int32) assert_type(b_ + i4, np.int32) assert_type(b + i4, np.int32) assert_type(AR_f + i4, npt.NDArray[np.float64]) -assert_type(i8 + u4, Any) -assert_type(i4 + u4, Any) -assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) +assert_type(i8 + u4, np.int64) +assert_type(i4 + u4, np.int64) +assert_type(u8 + u4, np.uint64) assert_type(u4 + u4, np.uint32) assert_type(b_ + u4, np.uint32) assert_type(b + u4, np.uint32) diff --git a/test/static/accept/bitwise_ops.pyi b/test/static/accept/bitwise_ops.pyi index 1d70fd3a..9c8a6c09 100644 --- a/test/static/accept/bitwise_ops.pyi +++ b/test/static/accept/bitwise_ops.pyi @@ -1,42 +1,41 @@ -from typing import Any, Literal as L, TypeAlias +from typing import Literal as L, TypeAlias from typing_extensions import assert_type import numpy as np import numpy.typing as npt -from numpy._typing import _32Bit, _64Bit FalseType: TypeAlias = L[False] TrueType: TypeAlias = L[True] i4: np.int32 -i8: np.int64 - u4: np.uint32 +i8: np.int64 u8: np.uint64 +b: bool +i: int b_: np.bool[bool] -b0_: np.bool[FalseType] -b1_: np.bool[TrueType] -b: bool b0: FalseType b1: TrueType - -i: int +b0_: np.bool[FalseType] +b1_: np.bool[TrueType] AR: npt.NDArray[np.int32] +### + assert_type(i8 << i8, np.int64) assert_type(i8 >> i8, np.int64) assert_type(i8 | i8, np.int64) assert_type(i8 ^ i8, np.int64) assert_type(i8 & i8, np.int64) -assert_type(i8 << AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(i8 >> AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(i8 | AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(i8 ^ AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(i8 & AR, npt.NDArray[np.signedinteger[Any]]) +assert_type(i8 << AR, npt.NDArray[np.signedinteger]) +assert_type(i8 >> AR, npt.NDArray[np.signedinteger]) +assert_type(i8 | AR, npt.NDArray[np.signedinteger]) +assert_type(i8 ^ AR, npt.NDArray[np.signedinteger]) +assert_type(i8 & AR, npt.NDArray[np.signedinteger]) assert_type(i4 << i4, np.int32) assert_type(i4 >> i4, np.int32) @@ -44,11 +43,11 @@ assert_type(i4 | i4, np.int32) assert_type(i4 ^ i4, np.int32) assert_type(i4 & i4, np.int32) -assert_type(i8 << i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(i8 >> i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(i8 | i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(i8 ^ i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) -assert_type(i8 & i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) +assert_type(i8 << i4, np.int64) +assert_type(i8 >> i4, np.int64) +assert_type(i8 | i4, np.int64) +assert_type(i8 ^ i4, np.int64) +assert_type(i8 & i4, np.int64) assert_type(i8 << b_, np.int64) assert_type(i8 >> b_, np.int64) @@ -68,11 +67,11 @@ assert_type(u8 | u8, np.uint64) assert_type(u8 ^ u8, np.uint64) assert_type(u8 & u8, np.uint64) -assert_type(u8 << AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(u8 >> AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(u8 | AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(u8 ^ AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(u8 & AR, npt.NDArray[np.signedinteger[Any]]) +assert_type(u8 << AR, npt.NDArray[np.signedinteger]) +assert_type(u8 >> AR, npt.NDArray[np.signedinteger]) +assert_type(u8 | AR, npt.NDArray[np.signedinteger]) +assert_type(u8 ^ AR, npt.NDArray[np.signedinteger]) +assert_type(u8 & AR, npt.NDArray[np.signedinteger]) assert_type(u4 << u4, np.uint32) assert_type(u4 >> u4, np.uint32) @@ -80,17 +79,17 @@ assert_type(u4 | u4, np.uint32) assert_type(u4 ^ u4, np.uint32) assert_type(u4 & u4, np.uint32) -assert_type(u4 << i4, np.signedinteger[Any]) -assert_type(u4 >> i4, np.signedinteger[Any]) -assert_type(u4 | i4, np.signedinteger[Any]) -assert_type(u4 ^ i4, np.signedinteger[Any]) -assert_type(u4 & i4, np.signedinteger[Any]) +assert_type(u4 << i4, np.int64) +assert_type(u4 >> i4, np.int64) +assert_type(u4 | i4, np.int64) +assert_type(u4 ^ i4, np.int64) +assert_type(u4 & i4, np.int64) -assert_type(u4 << i, np.signedinteger[Any]) -assert_type(u4 >> i, np.signedinteger[Any]) -assert_type(u4 | i, np.signedinteger[Any]) -assert_type(u4 ^ i, np.signedinteger[Any]) -assert_type(u4 & i, np.signedinteger[Any]) +assert_type(u4 << i, np.uint32) +assert_type(u4 >> i, np.uint32) +assert_type(u4 | i, np.uint32) +assert_type(u4 ^ i, np.uint32) +assert_type(u4 & i, np.uint32) assert_type(u8 << b_, np.uint64) assert_type(u8 >> b_, np.uint64) @@ -110,11 +109,11 @@ assert_type(b_ | b_, np.bool) assert_type(b_ ^ b_, np.bool) assert_type(b_ & b_, np.bool) -assert_type(b_ << AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(b_ >> AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(b_ | AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(b_ ^ AR, npt.NDArray[np.signedinteger[Any]]) -assert_type(b_ & AR, npt.NDArray[np.signedinteger[Any]]) +assert_type(b_ << AR, npt.NDArray[np.signedinteger]) +assert_type(b_ >> AR, npt.NDArray[np.signedinteger]) +assert_type(b_ | AR, npt.NDArray[np.signedinteger]) +assert_type(b_ ^ AR, npt.NDArray[np.signedinteger]) +assert_type(b_ & AR, npt.NDArray[np.signedinteger]) assert_type(b_ << b, np.int8) assert_type(b_ >> b, np.int8) @@ -122,8 +121,8 @@ assert_type(b_ | b, np.bool) assert_type(b_ ^ b, np.bool) assert_type(b_ & b, np.bool) -assert_type(b_ << i, np.int_) -assert_type(b_ >> i, np.int_) +assert_type(b_ << i, np.int8 | np.int_) +assert_type(b_ >> i, np.int8 | np.int_) assert_type(b_ | i, np.bool | np.int_) assert_type(b_ ^ i, np.bool | np.int_) assert_type(b_ & i, np.bool | np.int_) diff --git a/test/static/accept/mod.pyi b/test/static/accept/mod.pyi index c214eac5..334954a1 100644 --- a/test/static/accept/mod.pyi +++ b/test/static/accept/mod.pyi @@ -4,7 +4,6 @@ from typing_extensions import assert_type import numpy as np import numpy.typing as npt -from numpy._typing import _64Bit f8: np.float64 i8: np.int64 @@ -69,27 +68,27 @@ assert_type(divmod(m, AR_m), tuple[npt.NDArray[np.int64], npt.NDArray[np.timedel # Bool assert_type(b_ % b, np.int8) -assert_type(b_ % i, np.int_) -assert_type(b_ % f, np.float64) +assert_type(b_ % i, np.int8 | np.int_) +assert_type(b_ % f, np.int8 | np.int_ | np.float64) assert_type(b_ % b_, np.int8) assert_type(b_ % i8, np.int64) assert_type(b_ % u8, np.uint64) assert_type(b_ % f8, np.float64) assert_type(b_ % AR_b, npt.NDArray[np.int8]) -assert_type(divmod(b_, b), tuple[np.int8, np.int8]) assert_type(divmod(b_, b_), tuple[np.int8, np.int8]) # workarounds for https://github.com/microsoft/pyright/issues/9663 -assert_type(b_.__divmod__(i), tuple[np.int_, np.int_]) -assert_type(b_.__divmod__(f), tuple[np.float64, np.float64]) +assert_type(b_.__divmod__(b), tuple[np.int8, np.int8]) +assert_type(b_.__divmod__(i), tuple[np.int8, np.int8] | tuple[np.int_, np.int_]) +assert_type(b_.__divmod__(f), tuple[np.int8, np.int8] | tuple[np.int_, np.int_] | tuple[np.float64, np.float64]) assert_type(b_.__divmod__(i8), tuple[np.int64, np.int64]) assert_type(b_.__divmod__(u8), tuple[np.uint64, np.uint64]) assert_type(divmod(b_, f8), tuple[np.float64, np.float64]) assert_type(divmod(b_, AR_b), tuple[npt.NDArray[np.int8], npt.NDArray[np.int8]]) assert_type(b % b_, np.int8) -assert_type(i % b_, np.int_) -assert_type(f % b_, np.float64) +assert_type(i % b_, np.int8 | np.int_) +assert_type(f % b_, np.int8 | np.int_ | np.float64) assert_type(b_ % b_, np.int8) assert_type(i8 % b_, np.int64) assert_type(u8 % b_, np.uint64) @@ -97,8 +96,8 @@ assert_type(f8 % b_, np.float64) assert_type(AR_b % b_, npt.NDArray[np.int8]) assert_type(divmod(b, b_), tuple[np.int8, np.int8]) -assert_type(divmod(i, b_), tuple[np.int_, np.int_]) -assert_type(divmod(f, b_), tuple[np.float64, np.float64]) +assert_type(divmod(i, b_), tuple[np.int8, np.int8] | tuple[np.int_, np.int_]) +assert_type(divmod(f, b_), tuple[np.int8, np.int8] | tuple[np.int_, np.int_] | tuple[np.float64, np.float64]) assert_type(divmod(b_, b_), tuple[np.int8, np.int8]) assert_type(divmod(i8, b_), tuple[np.int64, np.int64]) assert_type(divmod(u8, b_), tuple[np.uint64, np.uint64]) @@ -108,44 +107,46 @@ assert_type(divmod(AR_b, b_), tuple[npt.NDArray[np.int8], npt.NDArray[np.int8]]) # int assert_type(i8 % b, np.int64) +assert_type(i8 % i, np.int64) +assert_type(i8 % f, np.int64 | np.float64) assert_type(i8 % i8, np.int64) -assert_type(i8 % f, np.float64 | np.floating[_64Bit]) -assert_type(i8 % f8, np.float64 | np.floating[_64Bit]) -assert_type(i4 % i8, np.int64 | np.int32) -assert_type(i4 % f8, np.float64 | np.float32) +assert_type(i8 % f8, np.float64) +assert_type(i4 % i8, np.int64) +assert_type(i4 % f8, np.float64) assert_type(i4 % i4, np.int32) assert_type(i4 % f4, np.float32) assert_type(i8 % AR_b, npt.NDArray[np.int64]) -assert_type(divmod(i8, b), tuple[np.int64, np.int64]) -assert_type(divmod(i8, i4), tuple[np.int64, np.int64] | tuple[np.int32, np.int32]) -assert_type(divmod(i8, i8), tuple[np.int64, np.int64]) # workarounds for https://github.com/microsoft/pyright/issues/9663 -assert_type(i8.__divmod__(f), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.float64, np.float64]) -assert_type(i8.__divmod__(f8), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.float64, np.float64]) -assert_type(divmod(i8, f4), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.float32, np.float32]) +assert_type(i8.__divmod__(b), tuple[np.int64, np.int64]) +assert_type(i8.__divmod__(i), tuple[np.int64, np.int64]) +assert_type(i8.__divmod__(f), tuple[np.int64, np.int64] | tuple[np.float64, np.float64]) +assert_type(i8.__divmod__(i4), tuple[np.int64, np.int64]) +assert_type(i8.__divmod__(i8), tuple[np.int64, np.int64]) +assert_type(i8.__divmod__(f8), tuple[np.float64, np.float64]) +assert_type(i8.__divmod__(f4), tuple[np.float64, np.float64]) assert_type(divmod(i4, i4), tuple[np.int32, np.int32]) assert_type(divmod(i4, f4), tuple[np.float32, np.float32]) assert_type(divmod(i8, AR_b), tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]) assert_type(b % i8, np.int64) -assert_type(f % i8, np.float64 | np.floating[_64Bit]) +assert_type(f % i8, np.int64 | np.float64) assert_type(i8 % i8, np.int64) assert_type(f8 % i8, np.float64) -assert_type(i8 % i4, np.int64 | np.int32) +assert_type(i8 % i4, np.int64) assert_type(f8 % i4, np.float64) assert_type(i4 % i4, np.int32) assert_type(f4 % i4, np.float32) assert_type(AR_b % i8, npt.NDArray[np.int64]) assert_type(divmod(b, i8), tuple[np.int64, np.int64]) -assert_type(divmod(f, i8), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.float64, np.float64]) +assert_type(divmod(f, i8), tuple[np.int64, np.int64] | tuple[np.float64, np.float64]) assert_type(divmod(i8, i8), tuple[np.int64, np.int64]) assert_type(divmod(f8, i8), tuple[np.float64, np.float64]) -assert_type(divmod(i4, i8), tuple[np.int64, np.int64] | tuple[np.int32, np.int32]) assert_type(divmod(i4, i4), tuple[np.int32, np.int32]) # workarounds for https://github.com/microsoft/pyright/issues/9663 -assert_type(f4.__divmod__(i8), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.float32, np.float32]) +assert_type(i4.__divmod__(i8), tuple[np.int64, np.int64]) +assert_type(f4.__divmod__(i8), tuple[np.float64, np.float64]) assert_type(f4.__divmod__(i4), tuple[np.float32, np.float32]) assert_type(AR_b.__divmod__(i8), tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]) @@ -153,7 +154,7 @@ assert_type(AR_b.__divmod__(i8), tuple[npt.NDArray[np.int64], npt.NDArray[np.int assert_type(f8 % b, np.float64) assert_type(f8 % f, np.float64) -assert_type(i8 % f4, np.floating[_64Bit] | np.float32) +assert_type(i8 % f4, np.float64) assert_type(f4 % f4, np.float32) assert_type(f8 % AR_b, npt.NDArray[np.float64]) diff --git a/test/static/reject/bitwise_ops.pyi b/test/static/reject/bitwise_ops.pyi index 8676e75d..a7081aa6 100644 --- a/test/static/reject/bitwise_ops.pyi +++ b/test/static/reject/bitwise_ops.pyi @@ -16,17 +16,17 @@ f8: Final[np.float64] = ... ~f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] -b1 >> f8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] -f8 >> b1 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] +b1 >> f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] +f8 >> b1 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] -i8 << f8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] -f8 << i8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] +i8 << f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] +f8 << i8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] f8 | i0 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] i0 | f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] -f8 ^ i8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] -i8 ^ f8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] +f8 ^ i8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] +i8 ^ f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] f8 & u8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue] u8 & f8 # type: ignore[call-overload] # pyright: ignore[reportOperatorIssue]