[Python-Dev] Class decorators (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 30 05:09:54 CEST 2006
- Previous message: [Python-Dev] Class decorators
- Next message: [Python-Dev] Class decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Phillip J. Eby wrote:
the readability of @decorators on the outside of a class tends to suck as the number of decorators and arguments increases.
So do decorators outside a function.
What's more, I haven't seen anybody posting any counterexamples to show that it doesn't suck for common use cases. Indeed, at the moment I don't even recall seeing any examples of class decorators being used without arguments!
Well, here's how my use case would look if I had class decorators:
@IOClass class MyClass: ...
Does that count? My decorator wouldn't need any arguments, because it looks inside the class for all the information it needs. [1]
That's actually a general solution to Phillip's concern: the decorator can always look for attributes in the class (or the class's dict if you don't want them inherited) for large amounts of information that wouldn't comfortably fit up the top. That's an extra degree of freedom that we don't have with functions.
[1] Actually I would probably give it one optional argument, the name to register under if different from the class name.
-- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiam! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing at canterbury.ac.nz +--------------------------------------+
- Previous message: [Python-Dev] Class decorators
- Next message: [Python-Dev] Class decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]