Introduction to Decorators: Power Up Your Python Code
summary
Step-by-step tutorial that actually shows working code, exercises, and a repo: implements timer trace register count_calls and a use_unit decorator with live fixes (args/*kwargs, return values, functools.wraps). Demonstrations use time.perf_counter, func_tools.wraps and the pint unit library and mention Flask/click/Numba patterns: uses time.perf_counter and functools.wraps and pint. Includes a striking demo where naive fib(32) causes ~7 million calls: fib(32) triggers ~7 million calls*. Code on GitHub runs as shown.
AI-written summary · about
chapters (33)
- 0:00Start
- 1:44What Are Decorators
- 3:26What this Course Will Include
- 4:18Introduction to Decorators
- 5:46Inner Functions
- 7:32Functions Are First Class Objects
- 11:43Reversed Print Function
- 21:57Inside Function
- 30:07Decorator Syntax
- 35:05Wrapper Decorator
- 44:19Decorator Factory
- 59:14Trace Decorator
- 1:00:59Random Greet
- 1:05:37Wrapper Function
- 1:07:33Test Cases
- 1:13:47Timer Decorator
- 1:21:08Register Decorator
- 1:23:01Rubber Language Parser
- 1:30:21Summary
- 1:32:54Using Classes as Decorators
- 1:34:34Count Calls
- 1:35:09Fibonacci Numbers
- 1:36:03Recursive Function
- 1:48:10Recap
- 1:49:08A Decorator Is a Function
- 1:50:42Adder Class
- 1:51:46Make a Class Callable
- 2:00:59Decorators in Classes
- 2:11:26Fifth Task
- 2:11:47Create Decorators That Can Take Arguments
- 2:16:25Unit Registry
- 2:18:44Cubase Units
- 2:24:29Create a Decorator
related talks
02h 21mIntroduction to Decorators: Power Up Your Python Code
02h 32mIntroduction to Decorators: Power UP Your Python Code
29mHow Decorators Function
02h 15mAll about decorators
29mOn the Use and Misuse of Decorators
29mMetaprogramming with Decorators, Metaclasses, and Dynamic Code Generation
01mDecorators Demystified
38mDecorators demystified
