8000 Make Timestamp hashable (#396) · eb-emilio/msgpack-python@9e5ec95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e5ec95

Browse files
authored
Make Timestamp hashable (msgpack#396)
When overriding __eq__, __hash__ should be overridden too.
1 parent 887d3a7 commit 9e5ec95

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

msgpack/ext.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Timestamp(object):
3636
3737
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
3838
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.
39+
40+
This class is immutable: Do not override seconds and nanoseconds.
3941
"""
4042

4143
__slots__ = ["seconds", "nanoseconds"]
@@ -78,9 +80,8 @@ def __eq__(self, other):
7880
)
7981
return False
8082

81-
def __ne__(self, other):
82-
"""not-equals method (see :func:`__eq__()`)"""
83-
return not self.__eq__(other)
83+
def __hash__(self):
84+
return hash((self.seconds, self.nanoseconds))
8485

8586
@staticmethod
8687
def from_bytes(b):

0 commit comments

Comments
 (0)
0