diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-12-12 19:59:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-12 19:59:06 +0900 |
commit | 9e5ec95e0292dce8485575310f6b69a618fdbefe (patch) | |
tree | ccc31738f4ac24b95d4c746a4d3189f6ca06f34e | |
parent | 887d3a7d22865d36d68fdcb5e653ea61d66f0b61 (diff) | |
download | msgpack-python-9e5ec95e0292dce8485575310f6b69a618fdbefe.tar.gz |
Make Timestamp hashable (#396)
When overriding __eq__, __hash__ should be overridden too.
-rw-r--r-- | msgpack/ext.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/msgpack/ext.py b/msgpack/ext.py index 00b759d..cc34fb2 100644 --- a/msgpack/ext.py +++ b/msgpack/ext.py @@ -36,6 +36,8 @@ class Timestamp(object): When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`. + + This class is immutable: Do not override seconds and nanoseconds. """ __slots__ = ["seconds", "nanoseconds"] @@ -78,9 +80,8 @@ class Timestamp(object): ) return False - def __ne__(self, other): - """not-equals method (see :func:`__eq__()`)""" - return not self.__eq__(other) + def __hash__(self): + return hash((self.seconds, self.nanoseconds)) @staticmethod def from_bytes(b): |