midPython
Decorators
Updated May 4, 2026
Short answer
Functions that modify other functions.
Deep explanation
A wrapper that executes code before and after the target function, typically used for logging, auth, or timing.
Real-world example
Checking if a user is logged in before allowing them to access an API route.
Common mistakes
- Forgetting to use @wraps from functools, which loses function metadata.
Follow-up questions
- Can you chain decorators?