Loading topic
functools.partial to pre-fill arguments, and that you know the difference between positional and keyword arguments. You will learn what a partial object stores, how it combines stored and new arguments at call time, and how to inspect it when debugging.2 min read@ symbol before. The next chapter shows what a simple decorator breaks, and the chapter after that fixes it with functools.wraps.2 min read@ syntax and know that functions are objects you can pass around and return. The earlier chapter on decorators covers both.2 min read*args, **kwargs. The previous chapter showed that such a decorator replaces the original function with the wrapper, and the original's name and docstring are lost. Here you fix that with functools.wraps.2 min read@ syntax and that you have seen functools.wraps used on an inner wrapper function. Here you will look at what wraps does internally and at the __wrapped__ attribute it leaves behind.2 min readdict key must be hashable. It explains the idea behind functools.cache before you meet the decorator itself.3 min read@ decorator syntax, and tell hashable types (tuple, str, int) from unhashable ones (list, dict, set). It builds on the earlier chapter on why caching function results helps.3 min readfunctools.cache works and that cache keys must be hashable. It covers lru_cache, which limits how many results are stored.3 min readfunctools.cache or functools.lru_cache to a function, as covered in the previous two chapters. It shows how to check whether a cache is working and how to empty it.2 min readfunctools.cache and lru_cache work, what hashable means, and how cache_info() reports hits and misses. Caching is safe only when its assumptions hold. Four common failures are unhashable arguments, impure functions, unbounded memory growth, and instance method3 min readpartial, wraps and cache in one program. It assumes you have read the earlier chapters: you know how partial fixes arguments, why functools.wraps keeps a decorated function's name and docstring, and how cache keys results by hashable arguments.2 min read