Type hints update
Type hints were my New Year’s Resolution for 2021 and I’ve learned a lot this year.
Whatever you want to know about typing, try to find it in the mypy documentation, not by googling. Typing has been evolving and continues to evolve, and anything you don’t find by checking the current docs is quite likely out of date.
What mypy catches for me:
- Sloppy thinking - if the correct type declaration for something exceeds the line length limit in your flake8 settings, you have written a truly terrible API.
- Sloppy error checking - did you declare something as
Optional
and then forget to have aNone
code path? You did, didn’t you… - Actual type mistakes (duh)
- False alarms or stuff I don’t quite know how to type hint correctly… Judicious use of
# type: ignore
is nothing to be ashamed of, IMHO. Especially if the problem is localized to a screenful of code that can be checked by inspection.