On Sun, Apr 19, 2020 at 7:48 AM boB Stepp <robertvst...@gmail.com> wrote: > Can you give guidelines or point to a good article how > to best and most efficiently use type annotation without > over-annotating? Bear in mind that I have yet to fully grasp all of > what mypy (What I am currently using.) can correctly infer from the > code. >
Like with most things, the best way is to start by doing as little as you possibly can, and then work your way up from there. Try using mypy on your code absolutely as-is, without any type hints at all. If it seems to be quite useless, add some hints, try again. Continue until it's able to help you with your goals. Oh, I forgot to mention. Start with a goal. Why are you using mypy? Is it to help you detect misspelled variable/parameter names? Is it to save you the hassle of writing unit tests? Is it to improve IDE features (tab completion etc)? The one specific thing I'll say is: function signatures are usually the lowest-hanging fruit. For equivalent effort, they'll usually give you the best results, since you can create "knowledge boundaries" of a sort, where the type inference doesn't need to search the entire codebase for everything. But other than that, just explore your own codebase to try to find where it'd be useful. ChrisA -- https://mail.python.org/mailman/listinfo/python-list