Type hints are not required for all modules at the moment in Home Assistant, but we aim to have complete coverage of the core modules.
Adding type hints to an existing codebase can be a daunting task. To speed this up and help developers doing this, Instagram made the
monkeytype program. It will analyze calls during runtime and try to assign the correct type hints to the code.
See this instagram blog post for a description of the workflow involved to use the monkeytype program.
We've added a script to start a run of our test suite or a test module and tell the
monkeytype program to analyze the run.
monkeytype stub homeassistant.your_actual_module.
- Look at output from the monkeytyped typing stub. If not totally bad, apply the stub to your module. You most likely will need to manually edit the typing in the last step.
monkeytype apply homeassistant.your_actual_module.
- Check the diff and manually correct the typing if needed. Commit, push the branch and make a PR.
Note: Applying a monkeytyped stub to a module that has existing typing annotations might error and not work. This tool is most useful for totally untyped modules.