fromfunctoolsimporttotal_orderingfromtypingimportSelfclassPerson:def__init__(self,name:str,age:int)->None:self.name=nameself.age=agedefwork(self)->None:print(f'{self.name} is working...')defeat(self)->None:print(f'{self.name} cannot eat right now, because they have to work...')defsleep(self)->None:print(f'{self.name} is now sleeping, but dreams about working...')defmain()->None:bob:Person=Person('Bob',35)luigi:Person=Person('Luigi',40)bob2:Person=Person('Bob',35)print(bob==luigi)# Falseprint(bob==bob2)# False
classPerson:def__init__(self,name:str,age:int)->None:self.name=nameself.age=agedefwork(self)->None:print(f'{self.name} is working...')defeat(self)->None:print(f'{self.name} cannot eat right now, because they have to work...')defsleep(self)->None:print(f'{self.name} is now sleeping, but dreams about working...')def__eq__(self,other:Self)->bool:returnself.__dict__==other.__dict__def__ne__(self,other:Self)->bool:returnnotself.__eq__(other)def__lt__(self,other:Self)->bool:return(self.name.lower(),self.age)<(other.name.lower(),other.age)def__gt__(self,other:Self)->bool:returnnotself.__lt__(other)andself!=otherdef__le__(self,other:Self)->bool:returnself.__lt__(other)orself.__eq__(other)def__ge__(self,other:Self)->bool:returnself.__gt__(other)orself.__eq__(other)
@total_orderingclassPerson:def__init__(self,name:str,age:int)->None:self.name=nameself.age=agedefwork(self)->None:print(f'{self.name} is working...')defeat(self)->None:print(f'{self.name} cannot eat right now, because they have to work...')defsleep(self)->None:print(f'{self.name} is now sleeping, but dreams about working...')def__eq__(self,other:Self)->bool:returnself.__dict__==other.__dict__def__lt__(self,other:Self)->bool:return(self.name.lower(),self.age)<(other.name.lower(),other.age)