mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
pyln: fix Millisatoshi div with msat itself
Before this patch this fails: `Millisatoshi(42) / Millisatoshi(2)` This is an operation that should return the ratio between the two operands as a float number. Same goes for __floordiv__ operator `//`. Changelog-None
This commit is contained in:
parent
f7cdf1dd98
commit
fffc343dd7
@ -176,13 +176,19 @@ class Millisatoshi:
|
||||
def __sub__(self, other: 'Millisatoshi') -> 'Millisatoshi':
|
||||
return Millisatoshi(int(self) - int(other))
|
||||
|
||||
def __mul__(self, other: int) -> 'Millisatoshi':
|
||||
def __mul__(self, other: Union[int, float]) -> 'Millisatoshi':
|
||||
if isinstance(other, Millisatoshi):
|
||||
raise TypeError("Resulting unit msat^2 is not supported")
|
||||
return Millisatoshi(floor(self.millisatoshis * other))
|
||||
|
||||
def __truediv__(self, other: Union[int, float]) -> 'Millisatoshi':
|
||||
def __truediv__(self, other: Union[int, float, 'Millisatoshi']) -> Union['Millisatoshi', float]:
|
||||
if isinstance(other, Millisatoshi):
|
||||
return self.millisatoshis / other.millisatoshis
|
||||
return Millisatoshi(floor(self.millisatoshis / other))
|
||||
|
||||
def __floordiv__(self, other: Union[int, float]) -> 'Millisatoshi':
|
||||
def __floordiv__(self, other: Union[int, float, 'Millisatoshi']) -> Union['Millisatoshi', int]:
|
||||
if isinstance(other, Millisatoshi):
|
||||
return self.millisatoshis // other.millisatoshis
|
||||
return Millisatoshi(floor(self.millisatoshis // float(other)))
|
||||
|
||||
def __mod__(self, other: Union[float, int]) -> 'Millisatoshi':
|
||||
|
Loading…
Reference in New Issue
Block a user