Python’s “type hints” are a bit of a disappointment to me
uninformativ.de
Python’s “type hints” are a bit of a disappointment to me
1–10 of 597 posts
Re: Python’s “type hints” are a bit of a disappointment to me
#2Most of the benefit of types goes away unless _everything_ is typed... my libraries, the libraries my libraries use, etc. I should be able to jump around in and out of library code following types and usages thereof in my IDE, making conclusions that are accurate based on what the types say.
When some of your libraries (or indirect dependencies) don't have types, you can no longer ever make any firm conclusions when exploring a complex codebase based on types. I want to change a method in the Widget type, and my IDE says it's used in 4 places. But in reality, that just means 4 or more places, who knows if there are others.
Adding types to a language that doesn't already have them is very hard for this reason. Until many years pass and they're in universal use, they add little value.
Re: Python’s “type hints” are a bit of a disappointment to me
#3Re: Python’s “type hints” are a bit of a disappointment to me
#4Re: Python’s “type hints” are a bit of a disappointment to me
#5Though I agree on its negative impact on the language ergonomics. It removes the joy of writing "scripting language" and as a statically typed language it is far from static-type-native ones.
Now I see it as a tax for compatibility: You enjoy dynamic typing at the beginning of the project, but you have to pay it back once you've grown up to a certain scale.
TypeScript to me feels much more like a native static typed language because it is. Does it help to be a transpiler? Maybe. But I would think that Hejlsberg just has done an astonishingly good work to make it compelling. Python's type annotation is good and completely reasonable, but gradual typing is such a hard problem and being good is probably not enough here.
Re: Python’s “type hints” are a bit of a disappointment to me
#6Re: Python’s “type hints” are a bit of a disappointment to me
#7Re: Python’s “type hints” are a bit of a disappointment to me
#8When I started learning PyCharm though, I discovered that type checking can actually work well in Python and it is not a waste of time at all. So I advise people now that unless you're using PyCharm, do not waste any time on type checking Python. In which case, have at it. I love it. PyCharm is really the only way to do type-checking productively right now.
Re: Python’s “type hints” are a bit of a disappointment to me
#9Re: Python’s “type hints” are a bit of a disappointment to me
#10Overall I do think type hints are worth it though, for maybe two benefits. They force you to look at the ridiculous types you are using, like `List[Union[None, str, List[Dict[str, str]]]]` which is the sort of thing that happens in codebases all the time. It adds just enough friction to push people to make explicit dataclasses or simplify function returns, which is good. Secondly they help with tracking functions which return None, which is a pain when following callstacks in big codebases.