-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
typing aliases for integer-like #18096
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
The defition of the Obviously this means that numpy/numpy/typing/_scalars.py Lines 10 to 17 in 1b8b46b
As a side note, mypy already considers from typing import overload, NoReturn
@overload
def func(a: complex) -> complex: ...
@overload
def func(a: float) -> NoReturn: ... |
I can't think of many situations where I'd want to use this though. NumPy itself is fairly inconsistent, e.g.:
I'd like all of that to consistently error where it casts to integer now. Which is not something we can easily do - but if we're going to expose an alias in |
This is why I asked data-apis/array-api#101 (comment) and data-apis/array-api#101 (comment). |
@rgommers If the plan is to expose them then I'd definitely agree with you. The current aliases are IMO too useful to remove in their entirety, so instead I'd propose to just give them a more apropiate. Perhaps something along the lines of |
|
When trying to use
numpy.typing
-provided aliases for integer-like scalars in scipy/scipy#10844 (review), I noticed thatnumpy.typing
doesn't have the right alias. It does have:but accepting bools as 0/1 where integers are expected isn't good practice.
Accepting integers for float-like is fine, and mypy does accept
int
if you annotate a variable asfloat
. Complex I'm not sure about, but I'd think it's undesirable to accept ints/floats for complex-like.The text was updated successfully, but these errors were encountered: