Loading topic
import from the standard library. Basic classes are only needed in later chapters.2 min read*args and **kwargs, and understand that a nested function can read variables from the function around it (a closure). The earlier chapters covered those ideas. Here you put them together.2 min read@ line does, and when it does it.2 min read*args and **kwargs forwarding and the @ syntax. Here you will see what a plain wrapper breaks and how functools.wraps fixes it.2 min readfunctools.wraps and that you know the @ syntax is shorthand for reassignment. Here you will see what happens when you put more than one decorator on the same function.2 min read@ syntax, and use functools.wraps. It also assumes you understand closures, where an inner function remembers variables from the function that created it.2 min read@name means f = name(f), and have seen a decorator factory such as repeat(times=3). Python ships several decorators that use these ideas. Knowing them saves you from rewriting what the standard library already does.2 min readfunctools.wraps and apply it with @. It also assumes you know what a closure is and how __init__ and __call__ work in a class.2 min read@ syntax works, and how classes define methods and attributes. A decorator can also be applied to a class. The idea is the same as for functions, but the decorator receives a class object instead of a function.3 min readfunctools.wraps, forward *args and **kwargs, and that you have seen async def and await. You don't need to know asyncio internals.2 min readfunctools.wraps, including a decorator factory, and that you know basic type hints such as Callable. The examples need Python 3.10 or newer. On older versions, import ParamSpec and Concatenate from typing_extensions.2 min readfunctools.wraps, and have seen decorator factories. Most decorator bugs come from a few mistakes. They are easy to fix once you know what each one looks like.2 min read