Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: fix unnecessarily broad integer binop return types #28065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions numpy/_typing/_callable.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,15 @@ class _IntTrueDiv(Protocol[_NBit1]):
class _UnsignedIntOp(Protocol[_NBit1]):
# NOTE: `uint64 + signedinteger -> float64`
@overload
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
def __call__(self, other: int, /) -> unsignedinteger[_NBit1]: ...
@overload
def __call__(self, other: int | signedinteger[Any], /) -> Any: ...
def __call__(self, other: float, /) -> float64: ...
@overload
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
def __call__(self, other: complex, /) -> complex128: ...
@overload
def __call__(
self, other: complex, /
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
def __call__(self, other: unsignedinteger[_NBit2], /) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ...
@overload
def __call__(
self, other: unsignedinteger[_NBit2], /
) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ...
def __call__(self, other: signedinteger, /) -> Any: ...

@type_check_only
class _UnsignedIntBitOp(Protocol[_NBit1]):
Expand Down Expand Up @@ -207,19 +203,13 @@ class _UnsignedIntDivMod(Protocol[_NBit1]):
@type_check_only
class _SignedIntOp(Protocol[_NBit1]):
@overload
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
@overload
def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ...
def __call__(self, other: int, /) -> signedinteger[_NBit1]: ...
@overload
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
def __call__(self, other: float, /) -> float64: ...
@overload
def __call__(
self, other: complex, /
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
def __call__(self, other: complex, /) -> complex128: ...
@overload
def __call__(
self, other: signedinteger[_NBit2], /
) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ...
def __call__(self, other: signedinteger[_NBit2], /) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ...

@type_check_only
class _SignedIntBitOp(Protocol[_NBit1]):
Expand Down Expand Up @@ -261,9 +251,7 @@ class _SignedIntDivMod(Protocol[_NBit1]):
@type_check_only
class _FloatOp(Protocol[_NBit1]):
@overload
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
@overload
def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ...
def __call__(self, other: int, /) -> floating[_NBit1]: ...
@overload
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
@overload
Expand Down
24 changes: 12 additions & 12 deletions numpy/typing/tests/data/reveal/arithmetic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ assert_type(c16 + AR_f, npt.NDArray[np.complexfloating[Any, Any]])
assert_type(f16 + c16, np.complex128 | np.complexfloating[_128Bit, _128Bit])
assert_type(c16 + c16, np.complex128)
assert_type(f8 + c16, np.complex128)
assert_type(i8 + c16, np.complexfloating[_64Bit, _64Bit])
assert_type(i8 + c16, np.complex128)
assert_type(c8 + c16, np.complex128 | np.complex64)
assert_type(f4 + c16, np.complex128 | np.complex64)
assert_type(i4 + c16, np.complex128 | np.complex64)
assert_type(i4 + c16, np.complex128)
assert_type(b_ + c16, np.complex128)
assert_type(b + c16, np.complex128)
assert_type(c + c16, np.complex128)
Expand Down Expand Up @@ -463,9 +463,9 @@ assert_type(f8 + AR_f, npt.NDArray[np.floating[Any]])

assert_type(f16 + f8, np.floating[_128Bit] | np.float64)
assert_type(f8 + f8, np.float64)
assert_type(i8 + f8, np.floating[_64Bit])
assert_type(i8 + f8, np.float64)
assert_type(f4 + f8, np.floating[_32Bit] | np.float64)
assert_type(i4 + f8, np.floating[_32Bit] | np.float64)
assert_type(i4 + f8,np.float64)
assert_type(b_ + f8, np.float64)
assert_type(b + f8, np.float64)
assert_type(c + f8, np.complex128 | np.float64)
Expand Down Expand Up @@ -502,17 +502,17 @@ assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
assert_type(i8 + u4, Any)
assert_type(i8 + b_, np.int64)
assert_type(i8 + b, np.int64)
assert_type(i8 + c, np.complexfloating[_64Bit, _64Bit])
assert_type(i8 + f, np.floating[_64Bit])
assert_type(i8 + c, np.complex128)
assert_type(i8 + f, np.float64)
assert_type(i8 + AR_f, npt.NDArray[np.floating[Any]])

assert_type(u8 + u8, np.uint64)
assert_type(u8 + i4, Any)
assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit])
assert_type(u8 + b_, np.uint64)
assert_type(u8 + b, np.uint64)
assert_type(u8 + c, np.complexfloating[_64Bit, _64Bit])
assert_type(u8 + f, np.floating[_64Bit])
assert_type(u8 + c, np.complex128)
assert_type(u8 + f, np.float64)
assert_type(u8 + AR_f, npt.NDArray[np.floating[Any]])

assert_type(i8 + i8, np.int64)
Expand All @@ -521,17 +521,17 @@ assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
assert_type(u4 + i8, Any)
assert_type(b_ + i8, np.int64)
assert_type(b + i8, np.int64)
assert_type(c + i8, np.complexfloating[_64Bit, _64Bit])
assert_type(f + i8, np.floating[_64Bit])
assert_type(c + i8, np.complex128)
assert_type(f + i8, np.float64)
assert_type(AR_f + i8, npt.NDArray[np.floating[Any]])

assert_type(u8 + u8, np.uint64)
assert_type(i4 + u8, Any)
assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit])
assert_type(b_ + u8, np.uint64)
assert_type(b + u8, np.uint64)
assert_type(c + u8, np.complexfloating[_64Bit, _64Bit])
assert_type(f + u8, np.floating[_64Bit])
assert_type(c + u8, np.complex128)
assert_type(f + u8, np.float64)
assert_type(AR_f + u8, npt.NDArray[np.floating[Any]])

assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
Expand Down
Loading