PEP 3107 – Function Annotations in Python 3
legacy.python.org
legacy.python.org
I guess I have to admit that my feeling is that in our rich existing language ecosystem, features that seem designed to help turn Python into something it isn't just waste time and steps Python that much closer to Enterprise-class complexity. Maybe what Python really needs most right now is just a straight-up language freeze. It's done, it is what it is, what it is is pretty darned good for a lot of use cases, and that last bit can't be highlighted enough. It isn't going to be a static language wonder, it isn't going to have generalized C-class performance, it isn't going to become a great hugely-concurrent multithreading language, and you know what? That's OK. It's better to be a good Python than to be a bad not-quite-anything.
from ensure import ensure_annotations
@ensure_annotations
def f(x: int, y: float) -> float:
return x+y
f(1, 2.3)
>>> 3.3
f(1, 2)
>>> ensure.EnsureError: Argument y to <function f at 0x109b7c710> does not match annotation type <class 'float'>
It's useful sometimes.I'm not a huge fan of the "->" syntax myself, but I'm not sure what would work better.
What changed to make this relevant now?
Python is increasingly losing ground to the new "it"-languages. To stay relevant, it needs cryptic syntax of dubious value so bloggers can write lengthy articles about useless applications for this new feature.
But then the stupidity of the statement would be immediately apparent.
So where are you getting your information that Python is losing to the "it" languages?
on the other hand, this could be quite useful for large (proprietary?) python codebases where common standards can be defined and rolled out and enforced.
And this looks a tad easier to find and understand than the standard docstring variable types description.