Q71: What sequence occurs when executing MyClass(*args) under the hood?

When executing MyClass(*args):

  1. Invokes metaclass __call__() (typically type.__call__).
  2. type.__call__ invokes MyClass.__new__(MyClass, *args) to allocate the object.
  3. If __new__ returns an instance of MyClass, it invokes MyClass.__init__(instance, *args).
  4. Returns the instance.
Key Takeaways
  • Triggers metaclass __call__ execution.
  • __new__ allocates instance; __init__ configures state.
Knowledge Check

What happens if __new__ returns an instance of a COMPLETELY DIFFERENT class?