Question on metaclasses

Steffen Glückselig usenet at gungfu.de
Sun Apr 24 07:25:59 EDT 2005


Hello,

I've been experimenting with metaclasses a bit (even though I am quite
a newbie to python) and stumpled over the following problem in my code:

class Meta(type):
  def __init__(cls, name, bases, dct):
    for attr, value in dct.items():
      if callable(value):
        dct[attr] = wrapper(value)

wrapper adds debugging-information to methods of the class (at least
that is my plan).

Using dct[attr] = wrapper(value) does not result in wrapped methods,
though. Using setattr(cls, attr, wrapper(value)) creates the desired
effect, though.

Why are the changes to dct not visible in the instantiated class? Is
dct not the namespace of the class currently instantiated?


best regards
Steffen




More information about the Python-list mailing list