Open Zac-HD opened 3 years ago
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
.
In #3336, Adrian spells out the precise steps:
- Install monkeytype and the pytest plugin:
pip install monkeytype pytest-monkeytype
.- Export an env var to tell MonkeyType to only look in the module we want:
export MONKEYTYPE_TRACE_MODULES=hypothesis.internal.conjecture
- Run tests:
pytest --monkeytype-output=./monkeytype.sqlite3 hypothesis-python/tests/conjecture
- Apply some type annotations:
monkeytype apply hypothesis.internal.conjecture.utils
- 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!
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:
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.