[Tutor] Metaclass programming

Orest Kozyar orest.kozyar at gmail.com
Mon Sep 3 22:08:20 CEST 2007


I have the following code:

class meta(type):

	def __call__(cls, *args, **kwargs):
		argnames = inspect.getargspec(cls.__init__)[0]
		for i, value in enumerate(args):
			kwargs[argnames[i]] = value
		return type.__call__(cls, kwargs)

class test(object):

	__metaclass__ = meta

	def __init__(self, x, y, **kwargs):
		pass

However, inspect.getargspec(cls.__init__) appears to return only the
arguments of the meta __init__ rather than the test __init__.  Is there any
way I can get access to the test __init__ function from the metaclass?

Orest



More information about the Tutor mailing list