Skip to content
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 annotations to hypothesis.internal.conjecture #3074

Open
Zac-HD opened this issue Aug 28, 2021 · 3 comments
Open

Add type annotations to hypothesis.internal.conjecture #3074

Zac-HD opened this issue Aug 28, 2021 · 3 comments
Labels
internals Stuff that only Hypothesis devs should ever see performance go faster! use less memory!

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Aug 28, 2021

The low-level engine behind Hypothesis is hypothesis.internal.conjecture. While well-commented, it can also be tricky to follow in places and I think that type annotations would make it easier to understand - especially with the variety of things called "data"!

This would be particularly valuable now because we're thinking about refactoring conjecture to add a "mid-level IR", which would improve our ability to detect redundancy (i.e. #1986 but more so) and support better integration with Crosshair.

Using a tool like MonkeyType to derive initial annotations from our tests would be pretty neat, though we'll still need careful review. autotype might be a better starting point, since it's fully static rather than using potentially-incomplete runtime data.

@Zac-HD Zac-HD added the internals Stuff that only Hypothesis devs should ever see label Aug 28, 2021
@Zac-HD Zac-HD added the performance go faster! use less memory! label Sep 6, 2021
@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 6, 2021

Adding the performance issue label because this unlocks experiments with e.g. the mypyc compiler, which could plausibly be a big win for bytestring-oriented code like conjecture.

https://glyph.twistedmatrix.com/2022/04/you-should-compile-your-python-and-heres-why.html suggests that this might be a big win.

https://ichard26.github.io/blog/2022/05/31/compiling-black-with-mypyc-part-1/ walks through the process of applying mypyc to black.

@Zac-HD
Copy link
Member Author

Zac-HD commented May 25, 2022

In #3336, Adrian spells out the precise steps:

  1. Install monkeytype and the pytest plugin: pip install monkeytype pytest-monkeytype.
  2. Export an env var to tell MonkeyType to only look in the module we want: export MONKEYTYPE_TRACE_MODULES=hypothesis.internal.conjecture
  3. Run tests: pytest --monkeytype-output=./monkeytype.sqlite3 hypothesis-python/tests/conjecture
  4. Apply some type annotations: monkeytype apply hypothesis.internal.conjecture.utils
  5. Review and adjust

Once we have all of hypothesis.internal.conjecture annotated, we should also try for a much stricter typechecking config on that section of the code. And once it all works, try compiling!

@adriangb
Copy link
Contributor

adriangb commented May 25, 2022

A couple notes from the first round of typing.
There's a couple instances of things that looks like they should be refactored in the future:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Stuff that only Hypothesis devs should ever see performance go faster! use less memory!
Projects
None yet
Development

No branches or pull requests

2 participants