More decorator rumination

Scott David Daniels Scott.Daniels at Acm.Org
Wed Mar 30 17:48:51 EST 2005


Over on comp.python.education we were discussing a (generally seen as)
misuse of decorators to build the definite integral of a function.
On thinking over the definite integral decorator, I had almost
decided that one necessary, but not sufficient, criterion for a
good decorator is that it must not change a function's arg list.
I was happy with this until just now.

I've been fighting wxPython a lot recently, and suddenly a good
working definition for a decorator came to me:

*  A decorator mediates between a function and its environment.

In particular, I thought about something like:

     @mousexy
     def OnRightClick(self, x, y):
         ...

For those non-wx'ers, all GUI events come wrapped in an "event",
so all event-responding methods tend to look like:

     def OnRightClick(self, event):
         x = event.GetX()
         y = event.GetY()

which looks like boilerplate to me.  I'm wondering whether others
think this is an interesting insight into what decorators are "for,"
or they think I'm working on "the moral equivalent of a macro."

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list