June 2017
Beginner to intermediate
274 pages
6h 49m
English
Annotations combine well with decorators because annotation values make a good way to provide input to a decorator, and decorator-generated wrappers are a good place to put code that gives meaning to annotations.
For example, let's rewrite the decorator example from the previous section. We'll switch to only accepting keyword arguments, just to keep the example relatively simple:

So, the adapted decorator encloses the function in a wrapper. This wrapper only accepts keyword arguments, which means that even, if the original function could accept positional arguments, they have to be specified by name. ...