Python - Function Calls involving Object Inheritance
Question: Suppose I have a parent class `foo` and an inheriting class `bar` defined as
such:

    
    
    class foo(object):
    
       def __init__(self, args):
          for key in args.keys():
             setattr(self, key, args[key])
          self.subinit()
    
       def subunit(self):
          pass
    
       ...
    

* * *
    
    
    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)
          ...
    
       ...
    

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


Answer: To answer my own question, I ran a test after adjusting the example a little:

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

* * *
    
    
    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
    

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

