How Decorators Function
summary
Live code shows decorators implemented as plain functions that take a callable and return a wrapper that uses args and kwargs, demonstrates fixing identity with functools.wraps, and builds practical examples: a tracer that prints entering/exiting, a timer, a decorator that calls a function twice, a parameterized repeat decorator, and a count_calls decorator that stores a persistent count attribute. Also covers decorating methods and classes, using @app.route for Flask endpoints, and test strategies including pytest.mark.parametrize* and isolated fake functions for unit tests.
AI-written summary · about
chapters (17)
- 0:00Intro
- 1:53Decorated Function
- 4:36Decorators Change Functions!
- 6:12Mistaken Identity?
- 6:59Inputs and Outputs?
- 8:50Adding a Timer
- 9:22Nesting Decorators
- 9:59Scrubbing and validating Arguments
- 11:19Decorators with Arguments
- 13:58Decorators in Classes
- 15:21Testing Decorators Testing decorators is challenging! Here's some advice
- 17:00Example Decorator Tests
- 19:31eclassmethod and @staticmethod
- 21:00The @property Decorator
- 23:24A Flask Example
- 24:19A pytest Example
- 26:43Decorator Candidates
related talks
29mOn the Use and Misuse of Decorators
02h 15mAll about decorators
03h 21mIntroduction to Decorators: Power Up Your Python Code
02h 21mIntroduction to Decorators: Power Up Your Python Code
02h 32mIntroduction to Decorators: Power UP Your Python Code
01mDecorators Demystified
38mDecorators demystified
24mA Taxonomy of Decorators: A-E
