Skip to content

Instantly share code, notes, and snippets.

View fgaudin's full-sized avatar

Francois Gaudin fgaudin

  • San Francisco, USA
View GitHub Profile
@fgaudin
fgaudin / decorators.md
Created May 31, 2017 19:10
Decorators in python

from @fgaudin blogpost that disappeared from the Internet

Probably like a lot of you, I’ve googled or checked Django’s code to know how to write my own decorators. And every time I was a bit confused, just copy/pasting the examples and changing the code until it works.

While working on a decorator which was basically an aggregation of other decorators, I’ve finally had to get a deeper understanding, so I’ll try to make it clear for you.

Decorators are functions

First, we’ll forget the annotation notation with the @ to understand them better. So when you do: