[New-bugs-announce] [issue29931] ipaddress.ip_interface __lt__ check seems to be broken

Sanjay report at bugs.python.org
Tue Mar 28 06:37:20 EDT 2017


New submission from Sanjay:

The less than check for ip_interface behavior seems weird. I am not sure if this is by design. We are just comparing the network address but when network address is equal we should compare the ip address.
The expectation is if a < b is False then b <= a must be True
>>> import ipaddress
>>> a = ipaddress.ip_interface("1.1.1.1/24")
>>> b = ipaddress.ip_interface("1.1.1.2/24")
>>> a < b
False
>>> b <= a
False
>>> a == b
False
>>> 
This happens with both v4 and v6
The tests were passing because in ComparisonTests we were testing with prefix length of 32 which means the whole ip address became the network address.
I have made a fix here:
https://github.com/s-sanjay/cpython/commit/14975f58539308b7af5a1519705fb8cd95ad7951
I can add more tests and send PR but before that I wanted to confirm the behavior.

----------
components: Library (Lib)
messages: 290695
nosy: Sanjay, ncoghlan, pmoody, xiang.zhang
priority: normal
severity: normal
status: open
title: ipaddress.ip_interface __lt__ check seems to be broken
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29931>
_______________________________________


More information about the New-bugs-announce mailing list