@@ -67,18 +67,17 @@ def __add__(self, other: T.Any) -> "Temp":
6767 if isinstance (other , (float , int )):
6868 other = type (self )(other )
6969 elif not isinstance (other , type (self )):
70- raise TypeError (
71- "can't add {} and {}" .format (repr (type (self )), repr (type (other )))
72- )
70+ return NotImplemented
7371
7472 # OFF + something is OFF
7573 if self .is_off or other .is_off :
7674 return type (self )(OFF )
77-
7875 return type (self )(self .value + other .value )
7976
8077 def __eq__ (self , other : T .Any ) -> bool :
81- return isinstance (other , Temp ) and self .value == other .value
78+ if not isinstance (other , type (self )):
79+ return NotImplemented
80+ return self .value == other .value
8281
8382 def __float__ (self ) -> float :
8483 if isinstance (self .value , float ):
@@ -90,21 +89,17 @@ def __hash__(self) -> int:
9089
9190 def __lt__ (self , other : T .Any ) -> bool :
9291 if isinstance (other , (float , int )):
93- other = Temp (other )
94-
92+ other = type (self )(other )
9593 if type (self ) is not type (other ):
96- raise TypeError (
97- "can't compare {} and {}" .format (repr (type (self )), repr (type (other )))
98- )
99-
94+ return NotImplemented
10095 if not self .is_off and other .is_off :
10196 return False
10297 if self .is_off and not other .is_off or self .value < other .value :
10398 return True
10499 return False
105100
106101 def __neg__ (self ) -> "Temp" :
107- return Temp (- self .value ) # pylint: disable=invalid-unary-operand-type
102+ return type ( self ) (- self .value ) # pylint: disable=invalid-unary-operand-type
108103
109104 def __repr__ (self ) -> str :
110105 if isinstance (self .value , (float , int )):
0 commit comments