This is easily disproven. If you're using PyCharm's or VScode's code completion, you're using type annotations. If you've seen your editor highlight a typo in the name of a function, same thing. If you want tools to be able to do the same with *your* code, you annotate it. 1/10 https://twitter.com/twiecki/status/1331556849204797444
As for "they never uncovered a single bug", if all you ever use are sporadic annotations, type checkers won't be able to help you much. But put enough annotations and tooling connects the dots, making plenty of errors evident. I will give you two fundamental examples. 2/10
The most common to me at least is when a None creeps in. Mypy (or PyRight in VScode) will let me know that there's a missing check. This might be a rare case, an "impossible" case, until it happens in the wild. Often the fix is not more annotations but some code refactoring. 3/10
The second bug often caught by type checkers is on the "return" boundary: one of your code paths forgets a return. This happens most often if your function is searching for something through iteration. You find it and return it! ...but what if you found nothing? 4/10
Type checking excels at catching those sorts of edge cases. Say you return a subtly different type to what you declared you would. For example, you declared a set[Element] as the return type but in one path you return a list. Maybe the caller would be lucky but who knows? 5/10
There's more but I want to move on. The thing is that those errors are caught as squiggly lines in your editor. You look at the highlighted error, slightly tap your forehead, fix the typo or forgotten edge case, and move on. It doesn't feel like a big deal. But it is! 6/10
Don't take my word on it! Microsoft spent a fortune and years of work of an industry giant (yes, I stan Anders Hejlsberg) to develop TypeScript. When I met him, he said that the most important piece of the puzzle is developer experience, IOW how seamless it is in use. 7/10
That same company is now developing powerful type checking and code completion for Python in VSCode. This effort employs a member of the Python Steering Council, and possibly also the creator of Python himself soon. You think they would settle for "illusion of productivity"? 8/10
I've seen codebases transformed by type annotations many times over in my career. First at Facebook with Hack. Then at Instagram with Python type annotations. Now at EdgeDB where our core database codebase is typed in over 70%. We do this is because the advantages are real. 9/10
And you do it, too, probably! Type annotations are a form of machine-checkable documentation. Good APIs document types *anyway*. You can see an example of this in the picture.

Annotations just move this information from a docstring to where it can realistically help you. 10/10
You can follow @llanga.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.