Skip to main content
Loading page…
Python Mastery
Chapter 8
Lesson 2 of 4
functools In Depth
Contents
Notes
Tutor
Note
Bridge: functools Imports and Decorator Labels
Loading activity…
Previous
1 / 12
Continue
Contents
Notes
Discussion
Tutor
34 min
12 activities
0 of 12 done
In this lesson
1
Bridge: functools Imports and Decorator Labels
2
functools.partial — Freezing Arguments
3
The @ Decorator Syntax — A Forward Reference
4
lru_cache and cache — Memoisation Done Right
5
Memoised Combinatorics
6
singledispatch — Type-Based Overloading
7
wraps, total_ordering, and reduce Pitfalls
8
Write a Decorator with wraps
9
Match functools Tools to Their Purpose
10
lru_cache Hashability
11
cached_property and __slots__ — A Subtle Trap
12
partial vs lambda for Argument Binding
Objectives
Use functools.partial to fix arguments and create specialised callables
Apply lru_cache and cache for memoisation and understand their performance implications
Use cached_property to defer expensive property computation
Implement singledispatch for type-based function overloading
Use functools.wraps to preserve function metadata in decorators
Use total_ordering to complete comparison operators from two
Chapter 8 · Functional Python & the functools Toolkit
Higher-Order Functions
functools In Depth
The operator Module & Function Composition
Pure Functions & Immutability
Previous: Higher-Order Functions
Next: The operator Module & Function Composition