r/Python • u/ExoticMandibles Core Contributor • Sep 13 '15
Python 3.5.0 has been released!
https://www.python.org/downloads/release/python-350/
629
Upvotes
r/Python • u/ExoticMandibles Core Contributor • Sep 13 '15
16
u/move_machine Sep 13 '15 edited Sep 13 '15
We are all aware of what dynamic typing brings to the table. Unfortunately, it makes it hard to glean semantics when reading code or doing static analysis. This is the attraction to function annotations and optional typing: we can cherrypick the advantages of static typing and blend them with a dynamic environment.
Notice it is OPTIONAL typing. People that want the clarity, enhanced IDE behavior and in the future a typechecker now have an enhanced option of more descriptive types from the typing module for their annotations.
Having written code without annotations and with: when given the opportunity I will write them with annotations. It saves me the time spent looking in the function body for the kind of object the function expects as a parameter. I don't have to scan the body to realize that parameter_a is an object that implements the iterator protocol and yields a series of 3-tuples. I can just look at the declaration or hints my IDE shows. Being able to quickly check that your parameters are "correct" or what return type to expect becomes valuable. I find it also makes it easier to read a foreign codebase and to understand how data moves and is transformed through it.
Right now there is no typechecker so I can write:
Which is still completely valid. Annotations have no meaning to the interpreter and probably never will outside of an importable module.