claritychallenge / clarity

Clarity Challenge toolkit - software for building Clarity Challenge systems
https://claritychallenge.github.io/clarity
MIT License
120 stars 51 forks source link

Improving type hints using MonkeyType and pytest-monkeytype #247

Open jonbarker68 opened 1 year ago

jonbarker68 commented 1 year ago

It would be great to have type hints used consistently throughout the codebase, but the cost of adding them has seemed prohibitive. However, I've found this great looking tool called MonkeyType that will do runtime analysis to generate type hint suggestions automatically and can then apply them to the code. It requires running all the code in the codebase, but there is a pytest plugin that will run MonkeyType during running the testsuite, so it's super easy to use.

It can be set up to overwrite or ignore existing suggestions, so as long as it's used with a bit of care it looks safe.

We could have a branch to run it across all the existing tests, and then just incorporate it into the workflow when working on new tests.

(There is also DropBox's pyannotate but this looks unmaintained and harder to use)

ns-rse commented 1 year ago

This looks like a great tool and well worth applying. The plugin looks invaluable and combined with the pre-commit hook running mypy would I hope make it pretty straight-forward to add.