laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve laforge: Looks good to me, approved
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.

Gerrit-MessageType: merged
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: Ic9e1f8af1db436af5456fe5964133a144c9e066b
Gerrit-Change-Number: 38204
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>