Metaclasses vs. standard Python reflection?

Pedro Rodriguez pedro_rodriguez at club-internet.fr
Wed May 7 03:18:22 EDT 2003


On Tue, 06 May 2003 21:40:37 +0200, David Mertz wrote:

> Pedro Rodriguez <pedro_rodriguez at club-internet.fr> wrote previously:
> |I disagree with you when you say that you don't touch the actual code
> |of the class, since you have to introduce the 'metaclass' inside the
> |class definition (or at last at module level of the class definition).
> 
> Nope.  See our article:
> 
>     http://www-106.ibm.com/developerworks/linux/library/l-pymeta.html
> 
> In particular, look at the function import_with_metaclass(), which is
> one of the little utility functions included in gnosis.magic (in Gnosis
> Utilities).
> 

I knew somebody must have already done this black magic ;) I should have
(and will) read your article, David.

But as far as my understanding of AOP goes, I am not comfortable with
the usage of metaclasses for this purpose. For instance, your function
will alter all classes of an imported module, where I expect an "aspect"
to be precisely targeted at some functions (I don't think it will be 
difficult to specialize your function for this purpose).

Some time ago, I posted in comp.lang.python some sets of function that
performed basic AOP without metaclasses and so worked even with python
1.5.2. This sticked basically to the 'setattr' ability which works on 
(most of) python methods/functions at object/class/module level.

Metaclasses just requires another level of abstraction which I don't see
the interest, except as a design requirement for a general framework.

Pedro




More information about the Python-list mailing list