-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Static typing issues with single array element return values #17798
Comments
The first issue (the return of The second issue is definitely a more pressing concern. For know, the only solution is to, unfortunately, is to set the return type to |
@BvB93 Possibly a stupid question: Could the typing of ufuncs be automated by code generation making use of a ufunc's |
Absolutely, in fact I have a branch somewhere that does something like that. |
@BvB93 Thanks for letting me know and for all your work on typing numpy! |
I have been trying out the new static typing stubs for one of my projects: Great work, thank you! This makes static type checking so much more useful.
There are two issues (or maybe a single underlying issue) I am frequently encountering in my code base:
__getitem__()
behaves effectively like a python float: It can be used in standard library functions that take floats. The current numpy typing stubs specifyAny
as return type which leads to plenty of issues at the intersection of numpy and the standard library.ufunc
return types are too wide: E.g.np.log10(10)
has return typegeneric
which is incompatible with float even though the return type is static in this case.Example code:
Static type checkers complain for both the last two lines like so:
I understand the difficulty of typing ufunc in general. That said, it would really be great if this could be made to work.
The text was updated successfully, but these errors were encountered: