4 ms·
The decision to put type annotations for variables in comments was made specifically for backwards compatibility reasons. Remember that Python has supported fu
by nchammas 11y ago
The decision to put type annotations for variables in comments was made specifically for backwards compatibility reasons.
Remember that Python has supported function annotations since 3.0 [0]. Python 3.5 will only add the option to type check those same annotations.
Any type annotations that can be checked by Python 3.5 can also be parsed by earlier versions of Python, though without being checked.
The only wart in this master plan is specifically the one where you want to type annotate variables (as opposed to functions). Comments are the only way they could do this in a backwards compatible way.
The Python devs are well aware of the ugliness of this compromise, which is why they end the section you linked to with this:
> If type hinting proves useful in general, a syntax for typing variables may be provided in a future Python version.
I can't comment on Go, but I wouldn't call Python's choice here unreasonable.
[0] https://www.python.org/dev/peps/pep-3107/ https://www.python.org/dev/peps/pep-3107/