From 6f4601041747e218629e56199dc26a8581b37397 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 28 Dec 2022 18:44:25 +0100 Subject: [PATCH] pyln-client: make Millisatoshi comparable to int This often helps the msat purge and pyln msat replacement mischmasch issues. I changed it in a way that the `AttributeError: 'int' object has no attribute 'millisatoshis'` Error will still be raised whever a `Millisatoshi` is compared to something else then a `Millisatoshi` or `int`. Changelog-None --- contrib/pyln-client/pyln/client/lightning.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index a81c930b5..d65640256 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -163,9 +163,13 @@ class Millisatoshi: return self.millisatoshis def __lt__(self, other: 'Millisatoshi') -> bool: + if isinstance(other, int): + return self.millisatoshis < other return self.millisatoshis < other.millisatoshis def __le__(self, other: 'Millisatoshi') -> bool: + if isinstance(other, int): + return self.millisatoshis <= other return self.millisatoshis <= other.millisatoshis def __eq__(self, other: object) -> bool: @@ -177,9 +181,13 @@ class Millisatoshi: return False def __gt__(self, other: 'Millisatoshi') -> bool: + if isinstance(other, int): + return self.millisatoshis > other return self.millisatoshis > other.millisatoshis def __ge__(self, other: 'Millisatoshi') -> bool: + if isinstance(other, int): + return self.millisatoshis >= other return self.millisatoshis >= other.millisatoshis def __add__(self, other: 'Millisatoshi') -> 'Millisatoshi':