?
=?iso-8859-2?B?TOl0ZXr1?=
I use Python 2.4.4. Please read the code below:
-----------------------------------------------------------
from new import classobj
def mymeta(name,bases,clsdict):
print 'meta: %s'%name
return classobj(name,bases,clsdict)
class A(object):
__metaclass__=mymeta
class B(A):
pass
-----------------------------------------------------------
This should print
meta: A
meta: B
when classes A and B are created. But only meta: B is missing,
since mymeta() is not called when class B is created.
Related python documentation states that mymeta() must be called when B is
created, since metaclasses are looked up in bases classes if not found in
the dictionary of the class itself.
found, uses its type)."
Thanks for your help.
Viktor
-----------------------------------------------------------
from new import classobj
def mymeta(name,bases,clsdict):
print 'meta: %s'%name
return classobj(name,bases,clsdict)
class A(object):
__metaclass__=mymeta
class B(A):
pass
-----------------------------------------------------------
This should print
meta: A
meta: B
when classes A and B are created. But only meta: B is missing,
since mymeta() is not called when class B is created.
Related python documentation states that mymeta() must be called when B is
created, since metaclasses are looked up in bases classes if not found in
the dictionary of the class itself.
its metaclass is used (this looks for a __class__ attribute first and if notFrom Python 2.4.4's manual: "Otherwise, if there is at least one base class,
found, uses its type)."
Thanks for your help.
Viktor