Metaclasses and new-style classes

Jordan Rastrick jrastrick at student.usyd.edu.au
Sun Aug 7 20:25:33 EDT 2005


Correct me if I'm wrong, but I think the OP was asking if metaclasses
work with old-style classes, not new-style.

jepler at unpythonic.net wrote:
> This may be a limitation Zope imposes.
>
> I wrote this program:
> #-----------------------------------------------------------------------
> class M(type):
> 	def __new__(*args):
> 		print "new M", args
>
> class T(object):
> 	__metaclass__ = M
> #-----------------------------------------------------------------------
>
> Running it prints
> new M (<class '__main__.M'>, 'T', (<type 'object'>,),
> 	{'__module__': '__main__', '__metaclass__': <class '__main__.M'>})
> ... so you can see that the __metaclass__ mechanism works just fine with
> new-style objects in plain Python.
> 
> Jeff




More information about the Python-list mailing list