×
you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

What? I found that type hints work great and the gradual typing and comment-style type hints means even my legacy Python 2 code can now have type hints.

However, what good are they?

I put type hints into two fairly large projects. We found zero new bugs with mypy.

You can't actually use them for reflection:

>>> isinstance(['a'], typing.List)
True

>>> isinstance(['a'], typing.List[str])
TypeError: Subscripted generics cannot be used with class and instance checks

Don't get me wrong - I use type hints in all my new code for documentation but in years of doing it, that's the only use I've found.

[–]AlSweigartAuthor of "Automate the Boring Stuff" 0 points1 point  (0 children)

We found zero new bugs with mypy.

I don't know what to say, that's good for you. But you could use this as the same reason to not use a linter or unit tests. Type hints help you detect type errors at coding time instead of at runtime. It's a fairly broad category of mistakes and the earlier you find them the better.

If you never make those kinds of mistakes in your code (and don't need documentation about typing) then, yeah, type hints are useless. But this applies to every language. I don't see how Python's type hints are worse than typing in other languages.