Re: Question on metaclasses

2005-04-24 Thread Reinhold Birkenfeld
Diez B. Roggisch wrote: > Reinhold Birkenfeld wrote: > >> Diez B. Roggisch wrote: class Foo(type): def __new__(cls, name, bases, dict): for k,v in [(k, v) for k,v in dict.items() if callable(v)]: cls.wrap(k,v,cls.get_directives(v), dict)

Re: Question on metaclasses

2005-04-24 Thread Steffen Glückselig
So dct is something like a template rather than the __dict__ of the actual class? I'd assume that changing the content of a dict would be possible even after it has been assigned to some object (here, a class). thanks and best regards Steffen -- http://mail.python.org/mailman/listinfo/python-l

Re: Question on metaclasses

2005-04-24 Thread Diez B. Roggisch
Reinhold Birkenfeld wrote: > Diez B. Roggisch wrote: >>> class Foo(type): >>> def __new__(cls, name, bases, dict): >>> >>> for k,v in [(k, v) for k,v in dict.items() if callable(v)]: >>> cls.wrap(k,v,cls.get_directives(v), dict) >>> >>> return super(Foo, self).__n

Re: Question on metaclasses

2005-04-24 Thread Reinhold Birkenfeld
Steffen Glückselig wrote: > Are wrap and get_directives somehow built-in? I couldn't find > references to them. > > I've noticed, too, that using __new__ I can manipulate the dictionary > resulting in the behavior I intented. > > I'd rather like to know: Why does it work in __new__ but not in > _

Re: Question on metaclasses

2005-04-24 Thread Steffen Glückselig
Are wrap and get_directives somehow built-in? I couldn't find references to them. I've noticed, too, that using __new__ I can manipulate the dictionary resulting in the behavior I intented. I'd rather like to know: Why does it work in __new__ but not in __init__? And, stimulated by your response

Re: Question on metaclasses

2005-04-24 Thread Reinhold Birkenfeld
Diez B. Roggisch wrote: >> class Foo(type): >> def __new__(cls, name, bases, dict): >> >> for k,v in [(k, v) for k,v in dict.items() if callable(v)]: >> cls.wrap(k,v,cls.get_directives(v), dict) >> >> return super(Foo, self).__new__(self, name, bases, dict) > > Th

Re: Question on metaclasses

2005-04-24 Thread Diez B. Roggisch
> class Foo(type): > def __new__(cls, name, bases, dict): > > for k,v in [(k, v) for k,v in dict.items() if callable(v)]: > cls.wrap(k,v,cls.get_directives(v), dict) > > return super(Foo, self).__new__(self, name, bases, dict) There is a confusion of self and cls

Re: Question on metaclasses

2005-04-24 Thread Diez B. Roggisch
Steffen Glückselig wrote: > 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

Question on metaclasses

2005-04-24 Thread Steffen Glückselig
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(