With the three arguments of the type function, you can create dynamically a new class (ie a type object).
type is a class that creates class objects
type.__class__
<class 'type'>
class type(name, bases, dict)
where:
class MyMinimalClass(object):
pass
type('MyMinimalClass', (), {})
The following two statements from the doc create two identical type objects with two attributes:
This code:
class X(object):
a = 1;
def echo(self):
print(self.a)
is identical with the below one.
def echo_a(self):
print(self.a)
X = type('X', (object,), dict(a=1,echo_a=echo_a))
# or
X = type('X', (object,), { 'a':1, 'echo_a': echo_a } )
FooChild = type('FooChild', (Foo,), {})
where: