title: Inheriting from instance in Python
body: <p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p>
  
  <pre><code>A = Parent(x, y, z)
  B = Child(A)
  </code></pre>
  
  <p>This is a hack that I thought might work:</p>
  
  <pre><code>class Parent(object):
  
      def __init__(self, x, y, z):
          print "INITILIZING PARENT"
          self.x = x
          self.y = y
          self.z = z
  
  class Child(Parent):
  
      def __new__(cls, *args, **kwds):
          print "NEW'ING CHILD"
          if len(args) == 1 and str(type(args[0])) == "&lt;class '__main__.Parent'&gt;":
              new_args = []
              new_args.extend([args[0].x, args[0].y, args[0].z])
              print "HIJACKING"
              return Child(*new_args)
          print "RETURNING FROM NEW IN CHILD"
          return object.__new__(cls, *args, **kwds)
  </code></pre>
  
  <p>But when I run </p>
  
  <pre><code>B = Child(A) 
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>NEW'ING CHILD  
  HIJACKING  
  NEW'ING CHILD  
  RETURNING FROM NEW IN CHILD  
  INITILIZING PARENT  
  Traceback (most recent call last):  
    File "classes.py", line 52, in &lt;module&gt;  
      B = Child(A)  
  TypeError: __init__() takes exactly 4 arguments (2 given) 
  </code></pre>
  
  <p>It seems the hack works just as I expected but the compiler throws a TypeError at the end. I  was wondering if I could overload TypeError to make it ignore the B = Child(A) idiom but I wasn't sure how to do that. In any case, would you please give me your solutions for inheriting from instances?</p>
  
  <p>Thanks!</p>