In Python3 it's possible to add the type to the arguments of a function:
def foo(bar: str = "default") -> str:
"""
@param bar: a textual value
"""
return "test"
Now I got two questions. First, how can you do that for a callback function? Meaning, how to define the signature of that callback in the function header?
def foo(callback) -> str:
"""
@param callback: function(value: str) -> str
"""
# calculate some intermediate stuff
my_var = ...
return callback(my_var)
Second, how to do that for tuples. This would include the defining that the value is of type tuple and should have two values (no triple etc.).
def foo(value) -> str:
"""
@param value: tuple of strings
"""
v1, v2 = value
return v1 + v2
Thanks for your comments and answers.
typing.Callable[[str], str]