Arguments for "type metaclass" __init__ method

Kaviraj Kanagaraj kaviraj at launchyard.com
Sun Jun 21 11:17:38 EDT 2015


Hi All,

I was reading about meta programming in "Pro Django" book.

I came across the "type" class which will be acting as default meta class
for all other class. Also "type" metaclass is where actuall class object is
created

To dynamically create a class:
DynamicClass = type("DynamicClass", (object,), {'eggs' : 'spams'})

which means type's __init__ method accepts ClassName, bases(tuple) and
attrbs(dict) as args.


But in case of creating class via class definition("type" act as default
metaclass), the type is called by following syntax,

type(cls, classname, bases, attrbs)

My doubt is how it possible to pass "cls" as argument(as class is not even
created before calling meta class). Also how "type" is accepting different
args in two different cases?

Need help in understanding

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150621/a97ae2c1/attachment.html>


More information about the Python-list mailing list