@@ -54,28 +54,30 @@ def _msat_to_sat(self, amount_msat: int | None) -> int | None:
5454 return int (Decimal (amount_msat ) / 1000 ) if amount_msat is not None else None
5555
5656 @pyqtProperty ('qint64' , notify = valueChanged )
57- def satsInt (self ):
57+ def satsInt (self ) -> int :
5858 if self ._amount_msat is None : # should normally be defined when accessing this property
5959 self ._logger .warning ('amount_msat is undefined, returning 0' )
6060 return 0
6161 return self ._msat_to_sat (self ._amount_msat )
6262
6363 @satsInt .setter
64- def satsInt (self , sats ):
64+ def satsInt (self , sats : int ):
65+ assert sats is None or isinstance (sats , int ), 'sats must be int or None'
6566 msats = self ._sat_to_msat (sats )
6667 if self ._amount_msat != msats :
6768 self ._amount_msat = msats
6869 self .valueChanged .emit ()
6970
7071 @pyqtProperty ('qint64' , notify = valueChanged )
71- def msatsInt (self ):
72+ def msatsInt (self ) -> int :
7273 if self ._amount_msat is None : # should normally be defined when accessing this property
7374 self ._logger .warning ('amount_msat is undefined, returning 0' )
7475 return 0
7576 return self ._amount_msat
7677
7778 @msatsInt .setter
78- def msatsInt (self , msats ):
79+ def msatsInt (self , msats : int ):
80+ assert msats is None or isinstance (msats , int ), 'msats must be int or None'
7981 if self ._amount_msat != msats :
8082 self ._amount_msat = msats
8183 self .valueChanged .emit ()
@@ -137,8 +139,7 @@ def lt(self, other: 'QEAmount|None') -> bool:
137139 if other is None :
138140 other = QEAmount ()
139141 assert isinstance (other , QEAmount )
140- if self .isMax or other .isMax :
141- return False
142+ assert not (self .isMax or other .isMax ), "'lt/lte' operator undefined for MAX amounts"
142143 if self .isEmpty and not other .isEmpty :
143144 return True
144145 return self .msatsInt < other .msatsInt
@@ -152,8 +153,7 @@ def gt(self, other: 'QEAmount|None') -> bool:
152153 if other is None :
153154 other = QEAmount ()
154155 assert isinstance (other , QEAmount )
155- if self .isMax or other .isMax :
156- return False
156+ assert not (self .isMax or other .isMax ), "'gt/gte' operator undefined for MAX amounts"
157157 if self .isEmpty and not other .isEmpty :
158158 return False
159159 return self .msatsInt > other .msatsInt
@@ -174,6 +174,13 @@ def max(self, one: 'QEAmount|None', two: 'QEAmount|None'):
174174 two = QEAmount ()
175175 assert isinstance (one , QEAmount )
176176 assert isinstance (two , QEAmount )
177+ # TODO: as gt/lt is undefined for operands being isMax, we can either
178+ # - raise (let the GUI avoid comparisons against MAX)
179+ # - define MAX as always being larger than any value
180+ if one .isMax :
181+ return one
182+ if two .isMax :
183+ return two
177184 return one if one .gt (two ) else two
178185
179186 @pyqtSlot ('QVariant' , 'QVariant' , result = 'QVariant' )
@@ -184,23 +191,30 @@ def min(self, one: 'QEAmount|None', two: 'QEAmount|None'):
184191 two = QEAmount ()
185192 assert isinstance (one , QEAmount )
186193 assert isinstance (two , QEAmount )
194+ # TODO: as gt/lt is undefined for operands being isMax, we can either
195+ # - raise (let the GUI avoid comparisons against MAX)
196+ # - define MAX as always being larger than any value
197+ if one .isMax :
198+ return two
199+ if two .isMax :
200+ return one
187201 return one if one .lt (two ) else two
188202
189- def __eq__ (self , other ):
190- if isinstance (other , QEAmount ):
191- return self ._amount_msat == other ._amount_msat and self ._is_max == other ._is_max
192- elif isinstance (other , int ):
193- return self ._amount_msat == other
203+ def __eq__ (self , other : 'QEAmount' ) -> bool :
204+ assert True if other is None else isinstance (other , QEAmount )
194205
195- return False
206+ if other is None :
207+ return False
196208
197- def __str__ (self ):
209+ return self ._amount_msat == other ._amount_msat and self ._is_max == other ._is_max
210+
211+ def __str__ (self ) -> str :
198212 s = _ ('Amount' )
199213 if self ._is_max :
200214 return '%s(MAX)' % s
201215 return '%s(sats=%s, msats=%s)' % (s , str (self ._msat_to_sat (self ._amount_msat )), str (self ._amount_msat ))
202216
203- def __repr__ (self ):
217+ def __repr__ (self ) -> str :
204218 return f"<QEAmount max={ self ._is_max } sats={ self ._msat_to_sat (self ._amount_msat )} msats={ self ._amount_msat } empty={ self .isEmpty } >"
205219
206220
0 commit comments