-
-
Notifications
You must be signed in to change notification settings - Fork 3k
"Invalid self argument" for numpy's iadd
#19171
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
Comments
@bersbersbers
|
It wouldn't be wrong necessarily, if I enumerated all possible integer types. Question is, why should I need to do that, considering that I also tried this, with varying success: from typing import Any
import numpy as np
import numpy.typing as npt
# works
def plus1a(array: npt.NDArray[np.signedinteger[Any]]) -> None:
array += 1
# works
def plus1b(array: npt.NDArray[np.unsignedinteger[Any]]) -> None:
array += 1
# fails
def plus1c(array: npt.NDArray[np.signedinteger[Any] | np.unsignedinteger[Any]]) -> None:
array += 1
# fails
def plus1d(array: npt.NDArray[np.integer[Any]]) -> None:
array += 1 |
It's defined as follows in the numpy stubs: @overload
def __iadd__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(
self: NDArray[unsignedinteger[Any]],
other: _ArrayLikeUInt_co | _IntLike_co,
/,
) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[signedinteger[Any]], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[float64], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[floating[Any]], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[complex128], other: _ArrayLikeComplex_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[complexfloating[Any]], other: _ArrayLikeComplex_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[timedelta64], other: _ArrayLikeTD64_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[datetime64], other: _ArrayLikeTD64_co, /) -> ndarray[_ShapeT_co, _DType_co]: ...
@overload
def __iadd__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DType_co]: ... So since there is no It's worth noting that pyright does not reject this. I'm guessing that it falls back to But even so, I agree that your example should be accepted by all type-checkers. I'll try to get this fixed before the upcoming numpy 2.3 release, but it might not make it in time (2.3 is about to be released). edit: see numpy/numpy#29092 |
@jorenham thanks for taking care of this. Just one bit:
I disagree at least partially - at least in my code base, this issue started appearing after 1.16.0 was released, and going back to 1.15.0 fixes it. Maybe my MWE above also triggers something in 1.15, but something definitely changed with 1.16. |
This will be fixed in the upcoming numpy 2.3.0 release. |
To Reproduce
Expected Behavior
No error
Actual Behavior
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: