Skip to content

Commit a3ed2e1

Browse files
committed
gh-134062: Fix hash collisions in IPv4Network and IPv6Network
1 parent 74c4e35 commit a3ed2e1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/ipaddress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def __eq__(self, other):
729729
return NotImplemented
730730

731731
def __hash__(self):
732-
return hash(int(self.network_address) ^ int(self.netmask))
732+
return hash((int(self.network_address), int(self.netmask)))
733733

734734
def __contains__(self, other):
735735
# always false if one is v4 and the other is v6.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`ipaddress`: fix collisions in :meth:`~object.__hash__` for
2+
:class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network`
3+
objects.

0 commit comments

Comments
 (0)