3 ms·
Well, the "type annotation" system, where you get to type variables but the types don't do anything, was expanded again. It doesn't improve safety. It doesn't i
by Animats 10y ago
Well, the "type annotation" system, where you get to type variables but the types don't do anything, was expanded again. It doesn't improve safety. It doesn't improve performance. The hand-waving argument is "Just as for function annotations, the Python interpreter does not attach any particular meaning to variable annotations and only stores them in the __annotations__ attribute of a class or module. In contrast to variable declarations in statically typed languages, the goal of annotation syntax is to provide an easy way to specify structured type metadata for third party tools and libraries via the abstract syntax tree and the __annotations__ attribute." Whatever that's supposed to mean.
I still suspect that was put in to screw over PyPy. If the type information was enforced, PyPy could use it to generate hard-typed code and improve performance. CPython, on the other hand, still represents everything as CObject objects in C. Type checking adds run-time overhead.
- jammycakes 10y agoThe Python interpreter itself may not do anything with the annotations, but static type checkers and linters can, and they will give you the safety that you need. The annotations also allow the development of better IntelliSense-like tools.
- baq 10y agothis comment reads much better if you replace Python with Javascript and PyPy with V8 or whatever, especially with today's Typescript announcement. additionally try using mypy-lang some. it's great.