PEP 318 - Function Modifier Syntax

Michele Simionato mis6 at pitt.edu
Wed Jun 11 10:46:10 EDT 2003


Robin Becker <robin at jessikat.fsnet.co.uk> wrote in message news:<w00taVAClg5+EwsI at jessikat.demon.co.uk>...
> In article <2259b0e2.0306100802.c805a50 at posting.google.com>, Michele
> Simionato <mis6 at pitt.edu> writes
> ....
> 
> in this scheme you're notationally overriding the __metaclass__ for the
> class, is there a default __metadef__ concept to go along with the
> methods?
> 
> is
> 
> class A:
>     __metadef__ = traced
> 
> ......
> 
> could make all of A's methods 'traced'.
> 

Esplicit is better than implicit and I would prefer to write an
explicit metaclass like that:

>>> from types import FunctionType
>>> class Traced(type):
	def __init__(cls,name,bases,dic):
		for name,func in dic.iteritems():
			if isinstance(func,FunctionType):
				setattr(cls,name,traced(func))

Notice that typically one does NOT want to trace all functions, but
only a given subset. The explicit metaclass gives much more control.
For instance I could modify it to trace only special methods, or
only staticmethods, or any combination I wish.

                                                         Michele




More information about the Python-list mailing list