by IceDane · 2w ago · 0 comments
"Python is not statically typed" doesn't really make sense, because if it is possible to build a static type-checker for python, then you can in fact write statically typed programs in Python, whether or not it is dynamic underneath. The same applies to TypeScript. If I have checked all the types in my program statically, I have written a statically typed program, regardless of whether javascript is dynamically typed underneath.
As for this project: I don't think it's useful because the type-checkers that exist for python have type inference. There is no particularly good reason to give every single thing a type annotation because it provides very little value.
In the end, the only question that is relevant for these sort of type-checkers that are built after the fact is really "Do they provide extra safety and value?" and the answer is very clearly a resounding "yes". Your theoretical gripes don't really have any bearing on that.
Regarding Python, I didn't even want to mention it because it'd not be fair. I could point out the shortcoming on Python type annotations: - Completely unsound (you can use `Any` everywhere) - lack of type-level evaluations: a `match` can't be type-annotated - Lack of variance expressiveness: can't declare variance on methods for example - etc...
But the answer regarding Python's type annotations shortcomings is basically "all of them", because it was not designed to be a statically typed language.
And regarding your question: "Do they provide extra safety and value?"
Sadly, it's not a yes/no answer. The answer is "it depends". For example, a method defined as `sum(l: List[Int])` cannot express if it works with an empty list, and depends on the value passed at runtime.
But in Lean you can define:
def sum (xs : Array Int) (_ : xs.size > 0) : Int :=
So the following expression doesn't even compile: #eval sum #[]
And funny enough, the research behind this is called "Dependent type research" [0].But again, my approach now is a lot more pragmatic. Similar to your question, mine is: can I break down this piece of software in very clearly defined contracts and layers and make it blow up at compile time if anybody violates these constraints or encapsulation? If the answer is "Yes", that's good with me. Python qualifies, Typescript qualifies (although I hate its type system more than python's, etc).