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
[TYP] return array dtype is always unkown but it's actually specified as parameter #3602
[TYP] return array dtype is always unkown but it's actually specified as parameter #3602
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'm looking forward to getting this in, though (per comments below) it might be a bit fiddly.
See also CONTRIBUTING.rst
, for how to create a RELEASE.rst
file with changelog (RELEASE_TYPE: patch
) and add your name to the list of authors 😁
@@ -37,6 +37,7 @@ | |||
from hypothesis.strategies._internal.numbers import Real | |||
from hypothesis.strategies._internal.strategies import T, check_strategy | |||
from hypothesis.strategies._internal.utils import defines_strategy | |||
from numpy.typing import DTypeLike, NDArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might increase our minimum supported numpy version. That's fine if we have to, but I think we could probably use an if TYPE_CHECKING:
block and string annotations to preserve compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I only checked for py37 compatibility.
NDArray was introduced in numpy 1.21 and DTypeLike in v1.20, v1.21 is from june 2022, I belive that's old enough,
I would personally introduce a install_requires=['numpy>=1.21']
in the setup.py, but the call is totally yours.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's as old as NEP-29
suggests supporting, which seems a quite principled way to make the decision. @honno do you have thoughts on this?
Regardless we should set our actual minimum version in extras_require
- I doubt we actually still support back to 1.9.0 - and think about setting up a minimum-numpy-version CI job. The CI job should be a separate PR though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's as old as NEP-29 suggests supporting, which seems a quite principled way to make the decision. @honno do you have thoughts on this?
I missed that, then we are good to go, no need for if TYPE_CHECKING
right?
) -> st.SearchStrategy[np.ndarray]: | ||
) -> st.SearchStrategy[NDArray[D]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also declare the shape here, for constant shapes... albeit by going from two to four overloads (value or strategy for each of two arguments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get away without overloads in this case, by defining another typevar for shape but honestly I would like to leave this point for now until we sort out the rest the comments you made in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, I'll be very happy to get in whatever improvement we have and write up an issue with the rest. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again Francesc! I'm sorry it took a while for me to get back to this, but delighted to be improving support for type-inference in our API 🙂
@Zac-HD sorry for the late reply, I was out of town. No worries I also left this pr on the side and didn't realize how close we were to get that CI green, thanks for the lint fixes! Until the next time 👋🙂 |
Given the following example
On master running the typechecker the ndarray dtype is unkown
If my understanding is correct, after this pr the dtype parameter will be taken into account.