Here’s what I submitted for a presentation topic for PyOhio:
TITLE: Decorators are fun
EXPERTISE LEVEL: Hopefully, there will be something for everyone. Novices might enjoy the material at the beginning mostly, while experts would likely be more interested in the ruledispatch discussion.
SUMMARY: This talk will start with a friendly walkthrough of decorators for people that have never seen them, then go into some straightforward examples, then finish with a review of how decorators are used in Philip Eby’s ruledispatch package.
- The simplest possible decorator.
- Pass arguments to a decorator.
- Write a decorator and still preserve the function signature of the decorated function.
- Coerce values into a function into types using decorators.
- Log values coming out of a function.
- Phillip Eby’s ruledispatch package implements generic functions, aka multimethods, for python. I’ll walk through how he uses decorators, and why they’re such a good idea for this.