title: Calling constructor of class as default argument in other class constructor
body: <h3>problem</h3>
  <p>I tried to call the constructor of a class inside another class' constructor's parameter's default assignment, but I encountered this problem where the constructor isn't called correctly. What is happening here?</p>
  <h3>code explanation</h3>
  <p>The <code>Bad</code> class is the case that doesn't work and the <code>Good</code> class is an ugly work around to solve the problem. The value <code>Base.i</code> is incremented for every time the constructor <code>Base.__init__</code> is called, and as can be seen, it isn't incremented correctly for the <code>o2</code> object, but it seems to be incremented correctly for each of <code>o1</code>, <code>o3</code> and <code>o4</code>.</p>
  <h3>code</h3>
  <pre><code>class Base:
      i = 0
      def __init__(self):
          Base.i += 1
          self.i = Base.i
  
  class Bad:
      def __init__(self, base = Base()):
          self.base = base
  
  class Good:
      def __init__(self, base = None):
          if base is None:
              self.base = Base()
          else:
              self.base = base
  
  if __name__ == &quot;__main__&quot;:
      o1 = Bad()
      o2 = Bad()
  
      print(&quot;Bad:&quot;)
      print(f&quot;o1.i: {o1.base.i}&quot;)
      print(f&quot;o2.i: {o2.base.i}&quot;)
  
      o3 = Good()
      o4 = Good()
  
      print(&quot;Good:&quot;)
      print(f&quot;o3.i: {o3.base.i}&quot;)
      print(f&quot;o4.i: {o4.base.i}&quot;)
  </code></pre>
  <h3>output</h3>
  <pre><code>o1.i: 1
  o2.i: 1
  Good:
  o3.i: 2
  o4.i: 3
  </code></pre>