From e699ebf017b332a9b6758f0fd99a38c942ec7dfd Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Wed, 30 Nov 2022 19:37:43 +0000 Subject: [PATCH] Test classes with diamond inheritance. --- main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 1d98040..93a666b 100644 --- a/main.py +++ b/main.py @@ -6,12 +6,26 @@ class Train: self.name = name if name else "#" def __str__(self): return f"Class {self.class_}({self.name})" + def manufacturer(self): + return "" -class C315(Train): - def __init__(self, name): - #Train.__init__(self, 315, name) - super().__init__(315, name) +class BREL(Train): + def __init__(self, class_): + super().__init__(class_, "") + def manufacturer(self): + return "BREL" -c315 = C315("Joe") -print(c315) +class PEP(Train): + def __init__(self, class_): + super().__init__(class_, "PEP") + def manufacturer(self): + return "Unknown" + +#The presendence of definitions is the order in the inheritance bracket +class C315(BREL, PEP): + def __init__(self): + super(BREL,self).__init__(315) + +c315 = C315() +print(c315, c315.manufacturer()) del c315