The metaclasses are responsible for the instantiation process.
- By default, the metaclass of any Python class is
type
. same asclass MyClass(metaclass=type)
Whenever, you do my_class = MyClass()
:
MyClass.__call__()
method is being called. This happens because in Python, calling an instance as a function, calls the__call__()
method of the class.- Inside the
MyClass.__call__()
method of the class:- The
MyClass.__new__()
method is being called to create a new instance. MyClass.__new__()
is a stub method calling the parent's.__new__()
, in this casetype.__new__()
).
- The