mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-25 06:34:10 +00:00
Make Timestamp hashable (#396)
When overriding __eq__, __hash__ should be overridden too.
This commit is contained in:
parent
887d3a7d22
commit
9e5ec95e02
1 changed files with 4 additions and 3 deletions
|
|
@ -36,6 +36,8 @@ class Timestamp(object):
|
||||||
|
|
||||||
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
|
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`.
|
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"]
|
__slots__ = ["seconds", "nanoseconds"]
|
||||||
|
|
@ -78,9 +80,8 @@ class Timestamp(object):
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __hash__(self):
|
||||||
"""not-equals method (see :func:`__eq__()`)"""
|
return hash((self.seconds, self.nanoseconds))
|
||||||
return not self.__eq__(other)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_bytes(b):
|
def from_bytes(b):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue