Python - Function Calls involving Object Inheritance
<p>Suppose I have a parent class <code>foo</code> and an inheriting class <code>bar</code> defined as such:</p>

<pre><code>class foo(object):

   def __init__(self, args):
      for key in args.keys():
         setattr(self, key, args[key])
      self.subinit()

   def subunit(self):
      pass

   ...
</code></pre>

<hr>

<pre><code>import math

class bar(foo):

   def __init__(self, arg1, arg2, ...):
      args = locals()
      del args['self']
      super(foo, self).__init__(args)

   def subunit(self):
      super(foo, self).subinit()
      self.arg1 = math.radians(self.arg1)
      self.arg2 = math.radians(self.arg2)
      ...

   ...
</code></pre>

<p>I have <code>bar</code> overriding the function <code>subinit</code> as it was defined by the parent class <code>foo</code>. However, since I am executing the line <code>self.subinit()</code> from inside the superclass constructor. I'm concerned that the <code>subinit</code> definition for <code>foo</code> will be used instead of the overridden <code>subinit</code> for <code>bar</code>. So my question, then, is this: What is the scope of execution here? If I call <code>subinit</code> from the superclass constructor, will it work in the scope of the totality of the instance and call <code>bar.subinit()</code> or will it work in the scope of the function and call <code>foo.subinit()</code></p>

<p>To answer my own question, I ran a test after adjusting the example a little:</p>

<pre><code>class foo(object):

   def __init__(self, args):
      for key in args.keys():
         setattr(self, key, args[key])
      self.subinit()

   def subinit(self):
      pass
</code></pre>

<hr>

<pre><code>class bar(foo):

   def __init__(self, arg1, arg2, arg3):
      args = locals()
      del args['self']
      super(self.__class__, self).__init__(args)

   def subinit(self):
      print self.arg1, self.arg2, self.arg3
</code></pre>

<p>The scope appears to be in the totality of the object, not just within the superclass. Therefore, <code>bar.subinit()</code> is getting called. Good to know.</p>

python class inheritance scope initialization