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
Add type hints to our public API (PEPs 484 & 561) #1270
Conversation
cb3d6c2
to
20c5eba
Compare
🎉, I finally got the build working! The solution is to set the CC @DRMacIver for review; it's mostly a matter of documentation and what counts as public API I think 😄 |
python/mypy#5218 is my report of (the first part I isolated of) the problem with |
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 really don’t know much about type hinting or Mypy or the like. This looks plausibly correct, but I don’t feel I’m qualified to give this a green tick.
hypothesis-python/docs/details.rst
Outdated
|
||
We may also find more precise ways to describe the type of various | ||
interfaces, or change their type and runtime behaviour togther in a way | ||
which is otherwise backwards-compatible. We often ommit type hints for |
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.
sp: “ommit”
whole-repo-tests/test_type_hints.py
Outdated
env=dict(os.environ, MYPYPATH=tools.PYTHON_SRC), | ||
).stdout.read() | ||
assert len(out.splitlines()) == 1 | ||
typ = out.split('error: Revealed type is ')[1].strip().strip("'") |
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 have no idea what Mypy successful or unsuccessful output looks like – a brief comment here with examples of both would help satisfy me that this string parsing code is working correctly.
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'll add a link to the docs and an example of the output we're parsing. (done)
6d58963
to
16c0026
Compare
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.
One question about a thing I didn't understand, otherwise LGTM.
whole-repo-tests/test_type_hints.py
Outdated
('booleans().filter(bool)', 'bool'), | ||
('lists(none())', 'list[None]'), | ||
('dictionaries(integers(), datetimes())', 'dict[int, datetime.datetime]'), | ||
('recursive(integers(), lists)', 'Union[list[Ex`-1], int]'), |
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.
What is Ex`-1
?
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.
Ex
is the type of the example which SearchStrategy
is generic and covariant in; and Ex`-1
appears to denote recursion in this type - that is, Ex`-1
== Union[list[Ex`-2], int]
and so on.
I'll add a comment to this effect...
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.
This looks sensible from a PEP 561 perspective (save the one suggestion). Also, mypy 0.620 should have editable install support FWIW.
hypothesis-python/setup.py
Outdated
@@ -86,7 +86,7 @@ def local_file(name): | |||
author_email='david@drmaciver.com', | |||
packages=setuptools.find_packages(SOURCE), | |||
package_dir={'': SOURCE}, | |||
# package_data={'': ['py.typed']}, # un-comment to release type hints | |||
package_data={'': ['py.typed']}, |
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 believe it is better to explicitly mark the package name this file is from.
Note: need more validation to enforce this
As suggested by Ethan Smith
The test could only pass if no padding was generated, so adding pattern boundaries makes matching faster and exact generation less flaky.
✨ Finally! 🎉 |
FWIW, support for editable installs just landed and will be in the next mypy release. |
This PR finally closes #200 🎉
For anyone manually exploring this PR, note that Mypy does not find hints installed in editable mode (
pip install -e .
); you have to do a straightpip install .
- see python/mypy#5007 for work on a fix. This does not affect our CI setup as we don't use editable mode there, but is annoying in local development.