Skip to content

Commit 968d831

Browse files
authored
Merge pull request #57 from ShadowJonathan/add_hash
add __hash__ function to Multiaddr
2 parents c57fb9b + a9f1af4 commit 968d831

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

multiaddr/multiaddr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def __str__(self):
170170
def __repr__(self):
171171
return "<Multiaddr %s>" % str(self)
172172

173+
def __hash__(self):
174+
return self._bytes.__hash__()
175+
173176
def to_bytes(self):
174177
"""Returns the byte array representation of this Multiaddr."""
175178
return self._bytes

tests/test_multiaddr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,9 @@ def test_zone():
355355

356356
maddr_from_bytes = Multiaddr(ip6_bytes)
357357
assert str(maddr_from_bytes) == ip6_string
358+
359+
360+
def test_hash():
361+
addr_bytes = Multiaddr("/ip4/127.0.0.1/udp/1234").to_bytes()
362+
363+
assert hash(Multiaddr(addr_bytes)) == hash(addr_bytes)

0 commit comments

Comments
 (0)