by lang · 14y ago · 0 comments
MyClass = MetaClass()
MyObject = MyClass()
Those two code blocks are effectively equivalent: class Quux(type):
#__metaclass__ = type is implicit
pass
class Qux(object):
__metaclass__ = Quux
pass
and: Quux = type('Quux', (type,), {})
Qux = Quux('Qux', (object,), {})
the __metaclass__ attribute merely puts in words what's the callable being called when the keyword class gets parsed and subsequently handled in the current namespace.This class/object unification is one of a bunch of unifications I find extremely satisfying when thinking about how Python ticks.