Hooks, aspect-oriented programming, and design by contract

Pedro Rodriguez pedro_rodriguez at club-internet.fr
Wed Jan 23 13:15:53 EST 2002


"Luigi Ballabio" <ballabio at mac.com> wrote:

> At 02:11 PM 1/23/02 +0100, Alex Martelli wrote:
>>I see no reason in Python why said object should necessarily be a class,
>>at least in Python and other languages allowing independent alterations
>>to instances (I think Ruby does that, and I wonder if Aspect/R supports
>>only class-level, or also instance level, aspecting/augmenting).
> 
> Hi,
>          it does support class or instance augmenting transparently,
>          i.e.,
> 
> aspect.wrap(SomeClass,precond,postcond,methods)
> 
> and
> 
> aspect.wrap(instance,precond,postcond,methods)
> 
 
I fixed my version to add also the ability for (modules,functions).

a remark and a question on python :

- it misses the 'around' wrapping, so that you may write something like :
  def wrapper(..., proceedFunc, *args, **kwargs):
      try:
          ...pre code...
          proceedFunc(*args, **kwargs)
      except:
          ...

- when giving the 'methods' arg in my code, I try to mimic AspectJ, 
  by giving a pattern, for instance, "*", so that all methods will be
  wrapped

  but I have a problem when giving an instance :
  - dir() on a class or a module will give me a list of attributes, and
    I will be able to filter the 'callables' so that I can do wrap
  - dir() won't give methods for an instance, but attributes
 
  What could be the proper idiom so that an instance is dealt properly ?
  Should I test if an object is a module or a class (new & old kind) to
  use dir() and use dir(obj.__class__) otherwise ? Seems uggly to me.

TIA, 
(back to Alex messages ;)
-- 

Pedro





More information about the Python-list mailing list