Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Type hints are not perfect, but IMO after using them for a while, they are significantly better than nothing.

If you do the legwork, you can get mypy[0] type-checking done on your codebase in a way that is similar to how TypeScript does type-checking. There are stub files that are provided by project maintainers that are then used by mypy to infer things like e.g the return type of a function.

Type hints are also inline in the code, and not technically comments. They can be retrieved from class attributes using facilities from the standard library [1] and can facilitate other tooling that is specific for your project or that are more general.

> And even then, if you're so thorough with your typing, why not just use a proper statically typed language?

That would remove a lot of the benefit of choosing Python. Python is dynamically typed. Type hints make it possible to do type checking statically, but with a lot of extra leg work (as I described above). Making Python itself statically typed is not something that would interest 99% of the Python community IMO.

[0] http://mypy-lang.org/

[1] https://docs.python.org/3/library/typing.html#typing.get_typ...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: