Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,8 @@ def __lt__(self, other):
if address_less is NotImplemented:
return NotImplemented
try:
return self.network < other.network
return (self.network < other.network or
self.network == other.network and address_less)
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
Expand Down Expand Up @@ -2100,7 +2101,8 @@ def __lt__(self, other):
if address_less is NotImplemented:
return NotImplemented
try:
return self.network < other.network
return (self.network < other.network or
self.network == other.network and address_less)
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
Expand Down
37 changes: 29 additions & 8 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,14 +1405,35 @@ def testAddressComparison(self):
ipaddress.ip_address('::2'))

def testInterfaceComparison(self):
self.assertTrue(ipaddress.ip_interface('1.1.1.1') <=
ipaddress.ip_interface('1.1.1.1'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1') <=
ipaddress.ip_interface('1.1.1.2'))
self.assertTrue(ipaddress.ip_interface('::1') <=
ipaddress.ip_interface('::1'))
self.assertTrue(ipaddress.ip_interface('::1') <=
ipaddress.ip_interface('::2'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') ==
ipaddress.ip_interface('1.1.1.1/24'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1/16') <
ipaddress.ip_interface('1.1.1.1/24'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') <
ipaddress.ip_interface('1.1.1.2/24'))
self.assertTrue(ipaddress.ip_interface('1.1.1.2/16') <
ipaddress.ip_interface('1.1.1.1/24'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
ipaddress.ip_interface('1.1.1.1/16'))
self.assertTrue(ipaddress.ip_interface('1.1.1.2/24') >
ipaddress.ip_interface('1.1.1.1/24'))
self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
ipaddress.ip_interface('1.1.1.2/16'))

self.assertTrue(ipaddress.ip_interface('::1/64') ==
ipaddress.ip_interface('::1/64'))
self.assertTrue(ipaddress.ip_interface('::1/64') <
ipaddress.ip_interface('::1/80'))
self.assertTrue(ipaddress.ip_interface('::1/64') <
ipaddress.ip_interface('::2/64'))
self.assertTrue(ipaddress.ip_interface('::2/48') <
ipaddress.ip_interface('::1/64'))
self.assertTrue(ipaddress.ip_interface('::1/80') >
ipaddress.ip_interface('::1/64'))
self.assertTrue(ipaddress.ip_interface('::2/64') >
ipaddress.ip_interface('::1/64'))
self.assertTrue(ipaddress.ip_interface('::1/64') >
ipaddress.ip_interface('::2/48'))

def testNetworkComparison(self):
# ip1 and ip2 have the same network address
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ Extension Modules
Library
-------

- bpo-29931: Fixed comparison check for ipaddress.ip_interface objects.
Patch by Sanjay Sundaresan.

- bpo-29953: Fixed memory leaks in the replace() method of datetime and time
objects when pass out of bound fold argument.

Expand Down