AOP and metaclasses

John Roth newsgroups at jhrothjr.com
Fri Feb 20 18:51:50 EST 2004


"Santiago Aguiar" <santi at netlabs.com.uy> wrote in message
news:9b5b9c27.0402200655.24b91718 at posting.google.com...
> Im trying to use AOP techniques on python but, even if I understand
> the idea behind metaclasses, I cant find a way to use AOP in a dynamic
> way.
>
> What im trying to do is to weave an aspect to a class at runtime, but
> i don't want to include any special code or definition in the class
> itself. Also, i want to do
> it just for some particular classes. Is there any way to do this?
>
> I know its possible to apply an aspect to all the classes by
> redefining __metaclass__, and that I can do the same with a single
> class by assigning to __metaclass__ inside the class definition.
> However, I want to avoid the last step, so i can apply the aspect to
> any class.
>
> thanks!!
>
> saludos! santiago.

I believe there is at least one AOP project out there somewhere.
I don't think you want to use metaclasses, though. If I wanted
to do that, I'd look at using descriptors, and installing them at
run time when I found I wanted to do the cut.

However, I'm not a big fan of AOP. I got my taste of intercepting
someone else's entry points in the '70s when I was hacking MVS.

John Roth





More information about the Python-list mailing list