On 3/27/06, Phillip J. Eby <[EMAIL PROTECTED]> 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/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to