Method Eval
in Child
class inherits from Parents
class; method FirstOrder
in Child
class calls method Eval
in Child
class. Codes:
class Parents:
def Eval(self, x):
return value, grad
class Child(Parents):
def Eval(self, x):
super(Child, self).Eval(x)
def FirstOrder(self, x, x0):
val, grad = self.Eval(x0)
return val + grad * (x-x0)
and get:
TypeError: cannot unpack non-iterable NoneType object
I know an easy solution is to change self.Eval(x0)
to super(Child, self).Eval(x0)
. But I want to know why. From my understanding, calling self.Eval(x0)
in FirstOrder
will lead to the definition of method Eval
in Child
class. Since it is well-defined, then it calls Eval
in Parents
class.