Just a few days ago, Dropbox open-sourced PyAnnotate, a Python library that observes the execution of a Python program and automatically outputs Python type annotations. PyAnnotate greatly simplifies the process of using a type-checker (e.g. Mypy) with a legacy codebase.

Meanwhile, Kensho engineers have been hard at work preparing to include Mypy into our development process. As part of this effort, we started building an internal tool very similar to PyAnnotate — we wanted to use our extensive pytest test suites to autogenerate type annotations for all our code.

Thanks to the team behind PyAnnotate, we no longer have to develop such a tool alone — instead, we intend to contribute to the PyAnnotate project. Our first contribution is pytest-annotate, a plugin for the popular pytest library that makes running PyAnnotate on your test suite as easy as:

pip install pytest-annotate py.test --annotate-output=./annotate.json

You can then use the generated output file with PyAnnotate as usual:

pyannotate --type-info ./annotate.json <path_to_code>

Happy annotating!

Interested in working on problems like this?

We’re hiring! Check out our careers page for details.

We also welcome pull requests for all of our open-source projects!