Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

meta is all relative and means 'beyond'. A metaclass being a class, it can itself have a metaclass, and so on, and they are all only objects, where the author's following excerpt embodies:

    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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: