4 ms·
I regularly wish python required some sort type indication for function parameters As others pointed out, Python has optional type annotations and has had them
by ubernostrum 8y ago
I regularly wish python required some sort type indication for function parameters
As others pointed out, Python has optional type annotations and has had them since 3.0. They're static-only (you don't get runtime type checking from them), though, and getting what you want out of them will effectively require every single function, method and variable in not just your codebase but in every third-party dependency and all of their dependencies to be annotated.
Also, annotating "complex objects" tends to be an unreadable mess. If you have lots of functions which take complex objects as arguments, rather than a more clear list of parameters, that's probably not going to be solved by type annotations; it will be solved by rewriting the functions. In other words, you probably will not be helped by:
def foo(o: HugeLongComplexTypeDefinition) -> OtherHugeLongComplexTypeDefinition
But you would be helped by:
def foo(widget: Widget, operation: WidgetOperation, tolerance: float) -> Widget