pedro_rodriguez at club-internet.fr
Tue Jan 22 05:10:03 EST 2002
"Mark McEahern" <marklists at mceahern.com> wrote:
> Pedro Rodriguez <pedro_rodriguez at club-internet.fr> wrote in message
> news:<pan.2002.01.13.11.22.54.248401.9857 at club-internet.fr>...
>> Pre/Post/Around methods : I posted a simple implementation for this, à
>> la AspectJ (Java) and AspectR (Ruby). And comparing with AspectJ, I am
>> sure Python can provide that kind of implementation in simple and
>> elegant way, in comparison with the compiler and language modification
>> AspectJ introduces.
>> This is an example of a patch to the current problem in Python 2.2...
> Pedro, I'm very delighted to find the sample code (reposted at the
> bottom of this message) you posted previously showing an implemention of
> Aspect. As you noted, the sample implementation does not work with
> new-style classes:
> class A(object):
> def f(self, x):
> print "real f", x
> aspect.wrap_around("around_advice", A, "f") a = A() a.f(1)
> Did you have a fix for that?
The only fix I have, is the latest CVS version of 'newmodule.c' fixed
Unfortunately I don't have any workaround. It took me a while to find out
that the 'new' module was a solution, and took me some time to use it
Maybe there is a better way to do it. The problem is that :
- you have to override the class method (A.f in the example)
- you have to keep track of the original method to call it on purpose
- you may have to call all of the aspects that wrap the original method
- the most difficult (to me) keep track of 'self', the A instance on
which the method is applied.
The last point is the one that forced me to use the new module. Probably
because Advice are implemented as class instances and do_aspect as a
method. I suspect the clumsiness in the call to AdviceXXX in Aspect
exhibit this problem.
I will try to think about a proper way to solve these things (if
More information about the Python-list