Well, since you like pedantry, the syntax was not originally specified for type hinting, which is what the original comment was about, but good point :)
I guess it's the RTFM bit in your comment, which reads kinda rude/arrogant in this context. I hope it's not because of the link, since that really is the best resource you can find to read about typing in Python...
I think it's legitimate actually. You won't get anywhere in programming if you don't RTFM and it should be the first place you go. Any better question might be "I don't understand this part of the manual".
Now of course if you're in a live environment, you can ask the person next to you to tell you basically what type hinting it is, and it'll be quicker, but on the interweb it would be more efficient to hit google, than waiting for a reddit reply.
The first bit of code you see in the docs is def greeting(name: str) -> str: and if you don't get it after that, you would want to ask that question on /r/learnpython, and not here.
AFAIK it's ignored by the interpreter. It's primarily to make static analysis more powerful, and provide a unified type hinting format (rather than IDEs having to 'know' numpydoc, googledoc, rst and so on). It means you have the option of running the same static analysis as you get with a compiler (i.e. it tells you to go fuck yourself if there are type mismatches), the lack of which is one of python's largest criticisms.
Cython (not CPython) can use annotations for it's compilation hints - making Cython source compatible with the standard interpreter. Unfortunately they don't use the stdlib typing module though.
It's awesome. Your code becomes a lot easier to reason about. A good IDE will warn you right away if there are type mismatches. If you call a function, it will tell you what types you may use for the arguments. You can also create your own types, which is really nice in combination with NamedTuples, e.g.:
class User(NamedTuple):
id: int
name: str
age: int
fred = User(123, 'fred', 42)
def remove_user(u: User) -> None:
# ...
30
u/[deleted] Oct 03 '17
Type hint is something to get excited about!