In the following code I instantiate RightPyramid as:
p = RightPyramid(base=2, slant_height=7)
p.area()
class Rectangle:
def __init__(self, length, width, **kwargs):
self.length = length
self.width = width
super().__init__(**kwargs)
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
class Square(Rectangle):
def __init__(self, length, **kwargs):
super().__init__(length=length, width=length, **kwargs)
class Triangle:
def __init__(self, base, height):
self.base = base
self.height = height
super().__init__()
def tri_area(self):
return 0.5 * self.base * self.height
class RightPyramid(Square, Triangle):
def __init__(self, base, slant_height, **kwargs):
self.base = base
self.slant_height = slant_height
kwargs["height"] = slant_height
kwargs["length"] = base
super().__init__(base=base, **kwargs)
def area(self):
base_area = super().area()
perimeter = super().perimeter()
return 0.5 * perimeter * self.slant_height + base_area
def area_2(self):
base_area = super().area()
triangle_area = super().tri_area()
return triangle_area * 4 + base_area
The RightPyramid _mro_ results in:
(__main__.RightPyramid,
__main__.Square,
__main__.Rectangle,
__main__.Triangle,
object)
My question is:
What is super()._init_(**kwargs) in Rectangle class calling? I think it calls the init from Triangle class, but Rectangle does not inherit from Triangle class; on the other hand it precedes Triangle in MRO