diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-10-09 07:53:52 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 07:53:52 -0600 |
commit | 0cefa592833151266d3e0fc2f258685280b0713b (patch) | |
tree | dc01ad9c7fc7714c438b8db3c9c2a88572a5bfa8 /numpy/typing/_callable.py | |
parent | 8d9a048d74df64a6ff9ee6b862d99a5fcb1257b2 (diff) | |
parent | d934c2620439cbcf9b6f19b6037c1c67346dd71f (diff) | |
download | numpy-0cefa592833151266d3e0fc2f258685280b0713b.tar.gz |
Merge pull request #17465 from BvB93/bitwise-ops
ENH: Add annotations for bitwise operations
Diffstat (limited to 'numpy/typing/_callable.py')
-rw-r--r-- | numpy/typing/_callable.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py index 0d876ae8d..7c2ee86cb 100644 --- a/numpy/typing/_callable.py +++ b/numpy/typing/_callable.py @@ -47,6 +47,7 @@ else: HAVE_PROTOCOL = True if HAVE_PROTOCOL: + _IntType = TypeVar("_IntType", bound=integer) _NumberType = TypeVar("_NumberType", bound=number) _NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number) _GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic) @@ -63,6 +64,14 @@ if HAVE_PROTOCOL: @overload def __call__(self, __other: _NumberType) -> _NumberType: ... + class _BoolBitOp(Protocol[_GenericType_co]): + @overload + def __call__(self, __other: _BoolLike) -> _GenericType_co: ... + @overload # platform dependent + def __call__(self, __other: int) -> Union[int32, int64]: ... + @overload + def __call__(self, __other: _IntType) -> _IntType: ... + class _BoolSub(Protocol): # Note that `__other: bool_` is absent here @overload # platform dependent @@ -105,6 +114,15 @@ if HAVE_PROTOCOL: @overload def __call__(self, __other: complex) -> complexfloating[floating]: ... + class _UnsignedIntBitOp(Protocol): + # TODO: The likes of `uint64 | np.signedinteger` will fail as there + # is no signed integer type large enough to hold a `uint64` + # See https://github.com/numpy/numpy/issues/2524 + @overload + def __call__(self, __other: Union[bool, unsignedinteger]) -> unsignedinteger: ... + @overload + def __call__(self, __other: Union[int, signedinteger]) -> signedinteger: ... + class _SignedIntOp(Protocol): @overload def __call__(self, __other: Union[int, signedinteger]) -> signedinteger: ... @@ -113,6 +131,9 @@ if HAVE_PROTOCOL: @overload def __call__(self, __other: complex) -> complexfloating[floating]: ... + class _SignedIntBitOp(Protocol): + def __call__(self, __other: Union[int, signedinteger]) -> signedinteger: ... + class _FloatOp(Protocol): @overload def __call__(self, __other: _FloatLike) -> floating: ... @@ -127,12 +148,15 @@ if HAVE_PROTOCOL: else: _BoolOp = Any + _BoolBitOp = Any _BoolSub = Any _BoolTrueDiv = Any _TD64Div = Any _IntTrueDiv = Any _UnsignedIntOp = Any + _UnsignedIntBitOp = Any _SignedIntOp = Any + _SignedIntBitOp = Any _FloatOp = Any _ComplexOp = Any _NumberOp = Any |