diff options
author | Bas van Beek <b.f.van.beek@vu.nl> | 2020-10-16 16:27:55 +0200 |
---|---|---|
committer | Bas van Beek <b.f.van.beek@vu.nl> | 2020-10-17 18:05:12 +0200 |
commit | a5f17578bc31caccce5c5113dae5d1994bab22e4 (patch) | |
tree | af3997c0ef5caebaf2d008e86f3632904da33e84 | |
parent | 3ebabec4a68f980bc680d8fa8445fb08aa350e79 (diff) | |
download | numpy-a5f17578bc31caccce5c5113dae5d1994bab22e4.tar.gz |
MAINT: Fixed a few issues with the `__call__`-based protocols
* Removed redundant `type: ignore` messages
* Set the return precision as `Union[_NBit_co, _NBit]`
* Type the precision of `builtins.int` operations as `Any`
-rw-r--r-- | numpy/typing/_callable.py | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py index 372a39928..e8c8615b5 100644 --- a/numpy/typing/_callable.py +++ b/numpy/typing/_callable.py @@ -50,6 +50,7 @@ else: if TYPE_CHECKING or HAVE_PROTOCOL: _NBit_co = TypeVar("_NBit_co", covariant=True, bound=NBitBase) + _NBit = TypeVar("_NBit", bound=NBitBase) _IntType = TypeVar("_IntType", bound=integer) _NumberType = TypeVar("_NumberType", bound=number) _NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number) @@ -59,7 +60,7 @@ if TYPE_CHECKING or HAVE_PROTOCOL: @overload def __call__(self, __other: _BoolLike) -> _GenericType_co: ... @overload # platform dependent - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__(self, __other: float) -> float64: ... @overload @@ -71,7 +72,7 @@ if TYPE_CHECKING or HAVE_PROTOCOL: @overload def __call__(self, __other: _BoolLike) -> _GenericType_co: ... @overload # platform dependent - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__(self, __other: _IntType) -> _IntType: ... @@ -80,7 +81,7 @@ if TYPE_CHECKING or HAVE_PROTOCOL: @overload def __call__(self, __other: bool) -> NoReturn: ... @overload # platform dependent - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__(self, __other: float) -> float64: ... @overload @@ -102,19 +103,19 @@ if TYPE_CHECKING or HAVE_PROTOCOL: @overload def __call__(self, __other: _FloatLike) -> timedelta64: ... - class _IntTrueDiv(Protocol[_NBit_co]): # type: ignore[misc] + class _IntTrueDiv(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> floating[_NBit_co]: ... @overload - def __call__(self, __other: int) -> Union[float32, float64]: ... + def __call__(self, __other: int) -> floating[Any]: ... @overload def __call__(self, __other: float) -> float64: ... @overload def __call__(self, __other: complex) -> complex128: ... @overload - def __call__(self, __other: integer[_NBit_co]) -> floating[_NBit_co]: ... + def __call__(self, __other: integer[_NBit]) -> floating[Union[_NBit_co, _NBit]]: ... - class _UnsignedIntOp(Protocol[_NBit_co]): # type: ignore[misc] + class _UnsignedIntOp(Protocol[_NBit_co]): # NOTE: `uint64 + signedinteger -> float64` @overload def __call__(self, __other: bool) -> unsignedinteger[_NBit_co]: ... @@ -128,80 +129,75 @@ if TYPE_CHECKING or HAVE_PROTOCOL: def __call__(self, __other: complex) -> complex128: ... @overload def __call__( - self, __other: unsignedinteger[_NBit_co] - ) -> unsignedinteger[_NBit_co]: ... + self, __other: unsignedinteger[_NBit] + ) -> unsignedinteger[Union[_NBit_co, _NBit]]: ... - class _UnsignedIntBitOp(Protocol[_NBit_co]): # type: ignore[misc] + class _UnsignedIntBitOp(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> unsignedinteger[_NBit_co]: ... @overload - def __call__( - self, __other: unsignedinteger[_NBit_co] - ) -> unsignedinteger[_NBit_co]: ... - @overload - def __call__( - self: _UnsignedIntBitOp[_64Bit], - __other: Union[int, signedinteger[Any]], - ) -> NoReturn: ... - @overload - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__(self, __other: signedinteger[Any]) -> signedinteger[Any]: ... + @overload + def __call__( + self, __other: unsignedinteger[_NBit] + ) -> unsignedinteger[Union[_NBit_co, _NBit]]: ... - class _SignedIntOp(Protocol[_NBit_co]): # type: ignore[misc] + class _SignedIntOp(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> signedinteger[_NBit_co]: ... @overload - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__(self, __other: float) -> float64: ... @overload def __call__(self, __other: complex) -> complex128: ... @overload def __call__( - self, __other: signedinteger[_NBit_co] - ) -> signedinteger[_NBit_co]: ... + self, __other: signedinteger[_NBit] + ) -> signedinteger[Union[_NBit_co, _NBit]]: ... - class _SignedIntBitOp(Protocol[_NBit_co]): # type: ignore[misc] + class _SignedIntBitOp(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> signedinteger[_NBit_co]: ... @overload - def __call__(self, __other: int) -> Union[int32, int64]: ... + def __call__(self, __other: int) -> signedinteger[Any]: ... @overload def __call__( - self, __other: signedinteger[_NBit_co] - ) -> signedinteger[_NBit_co]: ... + self, __other: signedinteger[_NBit] + ) -> signedinteger[Union[_NBit_co, _NBit]]: ... - class _FloatOp(Protocol[_NBit_co]): # type: ignore[misc] + class _FloatOp(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> floating[_NBit_co]: ... @overload - def __call__(self, __other: int) -> Union[float32, float64]: ... + def __call__(self, __other: int) -> floating[Any]: ... @overload def __call__(self, __other: float) -> float64: ... @overload def __call__(self, __other: complex) -> complex128: ... @overload def __call__( - self, __other: Union[integer[_NBit_co], floating[_NBit_co]] - ) -> floating[_NBit_co]: ... + self, __other: Union[integer[_NBit], floating[_NBit]] + ) -> floating[Union[_NBit_co, _NBit]]: ... - class _ComplexOp(Protocol[_NBit_co]): # type: ignore[misc] + class _ComplexOp(Protocol[_NBit_co]): @overload def __call__(self, __other: bool) -> complexfloating[_NBit_co, _NBit_co]: ... @overload - def __call__(self, __other: int) -> Union[complex64, complex128]: ... + def __call__(self, __other: int) -> complexfloating[Any, Any]: ... @overload def __call__(self, __other: Union[float, complex]) -> complex128: ... @overload def __call__( self, __other: Union[ - integer[_NBit_co], - floating[_NBit_co], - complexfloating[_NBit_co, _NBit_co], + integer[_NBit], + floating[_NBit], + complexfloating[_NBit, _NBit], ] - ) -> complexfloating[_NBit_co, _NBit_co]: ... + ) -> complexfloating[Union[_NBit_co, _NBit], Union[_NBit_co, _NBit]]: ... class _NumberOp(Protocol): def __call__(self, __other: _NumberLike) -> number: ... |