Function annotations
In this section, we'll take a look at how to associate metadata with functions beyond docstrings, which we discussed in Chapter 4, Basic Best Practices. In the previous section, one of our examples was a decorator that automatically passed all our decorated function arguments through an adapter.
That's pretty cool, but what if we want to handle each parameter differently?
Sure, we could pass a whole bunch of adapters to the wrapper, but it becomes ugly and clumsy as we start dealing with functions that accept more parameters. What we'd really like to do is attach metadata directly to a function's parameters. Fortunately, that's exactly what function annotations are for.
Function annotation syntax
The following code example shows off Python's function annotation syntax:Â

To associate a value with a parameter, we put a colon (:
) after the parameter name and then write an expression. This expression will be evaluated when the function is defined and the result stored along...