laforge submitted this change.
osmocom.utils: Make 'hexstr' type hashable
otherwise we couldn't use hexstr values as dict keys, for example
Change-Id: Ic9e1f8af1db436af5456fe5964133a144c9e066b
---
M src/osmocom/utils.py
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/osmocom/utils.py b/src/osmocom/utils.py
index a218e1b..009eb04 100644
--- a/src/osmocom/utils.py
+++ b/src/osmocom/utils.py
@@ -41,6 +41,10 @@
# make sure comparison is done case-insensitive
return str(self) == other.lower()
+ def __hash__(self):
+ # having a custom __eq__ method will make the type unhashable by default, lets fix that
+ return hash(str(self))
+
def __getitem__(self, val) -> 'hexstr':
# make sure slicing a hexstr will return a hexstr
return hexstr(super().__getitem__(val))
To view, visit change 38204. To unsubscribe, or for help writing mail filters, visit settings.