The answer to this question is probably "W-what!? What the !@#$-- Stop!! That's a terrible idea!", but I would like to hear your thoughts...
I have two classes and one inherits from the other.
class A(object):
def t1(self):
self.t2()
def t2(self):
print "A"
class B(A):
def t1(self):
super(B, self).t1()
def t2(self):
print "B"
>>> a = A()
>>> b = B()
>>> a.tl()
A
>>> b.t1()
B
In this example B.t1
calls the super
function, to call A.t1
, but when it hits self.t2()
, in the A.t1
function it returns to the B
class to perform B.t2()
How would I be able to force calls from the base class to stay in the base class? This is all I could come up with, and it works, but I'm thinking there's a better solution.
class A(object):
def t1(self):
if type(self) == A:
self.t2()
else:
super(type(self), self).t2()
def t2(self):
print "A"
class B(A):
def t1(self):
super(B, self).t1()
def t2(self):
print "B"
>>> a = A()
>>> b = B()
>>> a.tl()
A
>>> b.t1()
A