title: Using __new__ to override __init__ in subclass
body: <p>I'm interested in using the <code>__new__</code> functionality to inject code into the <code>__init__</code> function of subclasses. My understanding from the documentation is that python will call <code>__init__</code> on the instance returned by <code>__new__</code>. However, my efforts to change the value of <code>__init__</code> in the instance before returning it from <code>__new__</code> don't seem to work.</p>
  
  <pre class="lang-python prettyprint-override"><code>class Parent(object):
  
      def __new__(cls, *args, **kwargs):
          new_object = super(Parent, cls).__new__(cls)
          user_init = new_object.__init__
          def __init__(self, *args, **kwargs):
              print("New __init__ called")
              user_init(self, *args, **kwargs)
              self.extra()
          print("Replacing __init__")
          setattr(new_object, '__init__', __init__)
          return new_object
  
      def extra(self):
          print("Extra called")
  
  class Child(Parent):
  
      def __init__(self):
          print("Original __init__ called")
          super(Child, self).__init__()
  
  c = Child()
  </code></pre>
  
  <p>The above code prints:</p>
  
  <pre class="lang-none prettyprint-override"><code>Replacing __init__
  Original __init__ called
  </code></pre>
  
  <p>but I would expect it to print</p>
  
  <pre class="lang-none prettyprint-override"><code>Replacing __init__
  New __init__ called
  Original __init__ called
  Extra called
  </code></pre>
  
  <p>Why not?</p>
  
  <p>I feel like Python is calling the original value of <code>__init__</code>, regardless of what I set it to in <code>__new__</code>. Running introspection on <code>c.__init__</code> shows that the new version is in place, but it hasn't been called as part of the object creation.</p>