metaclass

Mark McEahern marklists at mceahern.com
Mon Apr 15 12:08:22 EDT 2002


[Greg Chapman]
> I got a bit boggled looking at the Trace metaclass.  However, if
> I understand it correctly, it may not be necessary in 2.2 to use
> a metaclass to trace all method calls.
> [...]
> class C(Traced):
>     def __init__(self, x=0): self.x = x
>     def m1(self, x): self.x = x
>     def m2(self, y): return self.x + y
>     __trace_output__ = sys.stdout
>

Greg, thanks for the reply.  This helps me be a little more explicit about
why I'd prefer a metaclass-based approach:

I want to be able to turn tracing on all at once for all classes within a
particular interpreter session, without having to wire them beforehand (say
by subclassing from Traced).  Of course, theoretically another approach
would be some sort of aspect-oriented solution, but there doesn't seem to be
any convergence on a canonical approach to that in Python.

Cheers,

// mark






More information about the Python-list mailing list