by rzimmerman · 4y ago · 0 comments
100% yes. It’s much better than the examples would lead you to believe. Mypy catches stuff like:
def f(arg: Optional[Object]):
arg.method() # type error
if arg is not None:
arg.method() # ok
It’s half the goodness of what you’d get from a well-typed language like Haskell or Rust but with the ability to say “trust me on this” and disable type checks for a line or two. Honestly I wish go tooling checked for nil pointer use as well as mypy unwraps optional values. Every time I add type hints and use mypy I find bugs. I would never make the case that type hints are better than a strongly typed language (especially with pattern matching), but it’s a great balance when writing python.https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&...
Also clearly a bit of unsoundness is way better than just no type annotations at all, which is the alternative.
https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1...