From 629ecdd5a9505c63e514960e21d1a435acf4fae7 Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Wed, 25 Jan 2017 16:56:07 +0100 Subject: [PATCH 1/2] Allow to hash extensions, thus allowing them as map keys. --- umsgpack.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/umsgpack.py b/umsgpack.py index c0647e0..a7ba5e5 100644 --- a/umsgpack.py +++ b/umsgpack.py @@ -123,6 +123,13 @@ def __str__(self): s += ")" return s + def __hash__(self): + """ + Allow to hash extensions, thus allowing them as map keys. + """ + return self.type.__hash__() + self.data.__hash__() + + class InvalidString(bytes): """Subclass of bytes to hold invalid UTF-8 strings.""" pass From d4b497226e4f9b57de43c65d3e8c007f4f26b32d Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Wed, 8 Feb 2017 12:24:57 +0100 Subject: [PATCH 2/2] Hash extension objects via Python's tuple hashing algorithm. --- umsgpack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umsgpack.py b/umsgpack.py index a7ba5e5..ddc5151 100644 --- a/umsgpack.py +++ b/umsgpack.py @@ -127,7 +127,7 @@ def __hash__(self): """ Allow to hash extensions, thus allowing them as map keys. """ - return self.type.__hash__() + self.data.__hash__() + return hash((self.type, self.data)) class InvalidString(bytes):