On 3/27/06, Phillip J. Eby <pje at telecommunity.com> wrote: > PyProtocols and the zope.interface package both support inline class > decorators called "class advisors". They don't require any special syntax, > and aren't much more complex than regular decorators. By defining an > advisor like this: > > from protocols.advice import addClassAdvisor > > def some_advisor(whatever_args): > def callback(cls): > print "I can modify",cls,"or replace it" > return cls > addClassAdvisor(callback) > > you can then use it in a class body like so: > > class SomeClass: > some_advisor("something") > > And the return value from 'callback' will replace SomeClass, just like a > decorator replaces the function it's called on. > > The implementation should work with any Python version from 2.2 up. I'm > not sure if it would work with IronPython. But if it doesn't, that would > be a good indication of feature(s) that IronPython is missing. ;) Just curious (and lazy): what magic is the implementation using that makes this work without a custom metaclass? -- --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4