laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/python/pyosmocom/+/38204?usp=email )
Change subject: osmocom.utils: Make 'hexstr' type hashable
......................................................................
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(-)
git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/04/38204/1
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
https://gerrit.osmocom.org/c/python/pyosmocom/+/38204?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: Ic9e1f8af1db436af5456fe5964133a144c9e066b
Gerrit-Change-Number: 38204
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>