by bkeroack · 11y ago · 0 comments
This allows me to write Python in a design-by-contract style with full, rich runtime type checks. My bug count has gone down dramatically, and when I do find a bug it's virtually always via a typecheck exception.
Optional type checking as a first-class citizen is a great tool to have, and it's good to see the syntax standardized.
But as alluded to in the Reddit thread, there are serious issues with this PEP. The use of comments and the lack of runtime type checking from the start not only limits the potential of this particular PEP, but undermines future efforts to bring that functionality in.
IMO it would have been better to put in the work and properly integrate type checking decorations into the interpreter and the grammar. The tack-on comments at the end of the line are especially un-Pythonic and jarring.
Edit: Just saw the string literal based forward references. Ugh. Another problem in the making.
I use Python a lot and it has its uses, but adding this type hint stuff just seems like an enabler for causing myself pain and denial when I should be using a more strongly typed language.
You likely meant "dynamic", not "weak". See here:
wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language
Even if people are only using it as a shim for what could be static typechecking, I think there's something to say about the practicality of it existing, if only for the reason that their ecosystem might already be Python-based.
Maybe you should reconsider yours?
If you look at how popular go is among pythonistas, it kind of shows that the issue was really a lack of type inference more than anything else.
A good summary what's wrong with the type systems of the java era: http://www.slideshare.net/ScottWlaschin/c-light
Joking? Python really is almost the last of all dynamic languages to come up with syntax for that. common lisp, scheme, perl, ruby, javascript, php have all syntax for optional typing already, only Guido was against it for years. Which eventually led to Go being developed by Google, and python's downfall. They try to catchup now, but this proposal is only 10% of an optional type system. I miss the inferencer and the optimizations still.
Inevitably my code will produce results of the right type, but have a logical error that makes either the answer flat out wrong or more or less inaccurate based on our cloud requirements.