~/talk

How Decorators Function

Talkat PyCon India 2020 · 2020-10-02..10-05· [python, compilers-and-language-design]
slides:none on file

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

  1. 0:00Intro
  2. 1:53Decorated Function
  3. 4:36Decorators Change Functions!
  4. 6:12Mistaken Identity?
  5. 6:59Inputs and Outputs?
  6. 8:50Adding a Timer
  7. 9:22Nesting Decorators
  8. 9:59Scrubbing and validating Arguments
  9. 11:19Decorators with Arguments
  10. 13:58Decorators in Classes
  11. 15:21Testing Decorators Testing decorators is challenging! Here's some advice
  12. 17:00Example Decorator Tests
  13. 19:31eclassmethod and @staticmethod
  14. 21:00The @property Decorator
  15. 23:24A Flask Example
  16. 24:19A pytest Example
  17. 26:43Decorator Candidates
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.