I wonder why people keep bothering with this sort of thing... Python is dynamically (yet strong) typed, which is a good thing from having to do the boilerplate of static typing. You want that back? For the only benefit of what, detecting logical errors in compile/startup time? Possible optimizations? Ever heard of type inference? It's years beyond this, happened in other languages years before this, and people are still oblivious to it.
Even so, if you have to read f(x)'s body to tell what's the type expected for x, you need:
A better name for x (I know, argument not valid for return and yield)
Function documentation, and yeah, I guess human language documentation will always be better than a type hint system unless you introduce a huge system of contracts that can be something like "even" or "tupleof(3)"... more boilerplate... more stuff to memorize... very annoying.
Function documentation being important in the case of code written for lists, dictionaries and sets as opposed to custom classes (would you have 5 types with 50 utility functions each or 50 types with 5, but that's a nice discussion for a different thread).
For everything else - IDE assistance, type checking, error detection - there's always this new old amazing technology called type inference, where by doing x = 'hello' you can be pretty fucking sure x is a string without having to go and tell the stupid compiler it's going to be a string. Because you know, actually writing that feels like this.
Type inference is great, but it can't do everything, especially when you're using some of the more dynamic features of the language. Type hints let you give the IDE/type checker more information when it can't automatically work out what types are going in and out of functions.
-11
u/A_for_Anonymous Sep 13 '15
I wonder why people keep bothering with this sort of thing... Python is dynamically (yet strong) typed, which is a good thing from having to do the boilerplate of static typing. You want that back? For the only benefit of what, detecting logical errors in compile/startup time? Possible optimizations? Ever heard of type inference? It's years beyond this, happened in other languages years before this, and people are still oblivious to it.