A showcase of Python decorators including timing, logging, retry, and memoization decorators with both function and class patterns.
python examples.py- Function decorators with
@syntax - Decorator factories with arguments
functools.wrapspattern- Timing and logging decorators
- Retry decorator with configurable attempts
You will learn how decorators work, when to use them, and how to build reusable decorators for cross-cutting concerns.
24-decorators/
README.md
decorators.py
examples.py
Decorator Showcase
------------------
[TIMER] slow_function took 2.003 seconds
[LOG] add(3, 5) called -> returned 8
[RETRY] Attempt 1 failed: Connection error
[RETRY] Attempt 2 succeeded
[CACHE] fibonacci(10) computed -> 55
[CACHE] fibonacci(10) returned cached -> 55