My proposed talk for PyOhio

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.

OUTLINE:

  • 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.

5 thoughts on “My proposed talk for PyOhio

  1. Sounds like a good talk topic!

    As someone who’s written more than my fair share of decorators, can I also suggest mentioning some of the pitfalls (like argument introspection might not work the way it did pre-decoration, and that order of decorators can make a difference).

    Paver and TurboGears 2 use the decorator syntax to keep track of behavior that you want applied without being true “decorators”. I believe TG2 uses *a* decorator and the rest just keep track of how you want things to behave. Paver’s decorators do not actually alter the function at all.

  2. Hi Kevin — thanks for the idea to talk about the pitfalls. I think I will add a section for that (if I get picked).

    I’ll have to study how pavers uses decorators without altering the function. Sounds like a neat idea. I’m speculating that the decorator alters some other data structure.

  3. FYI, you might also want to look at DecoratorTools (which is used by RuleDispatch to implement its decorators) and PEAK-Rules (which is a modern replacement for RuleDispatch, also based on DecoratorTools).

Comments are closed.