classification
Title: ipaddress.ip_interface __lt__ check seems to be broken
Type: behavior Stage: backport needed
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mariatta, Sanjay, berker.peksag, ncoghlan, pmoody, serhiy.storchaka, xiang.zhang
Priority: normal Keywords:

Created on 2017-03-28 10:37 by Sanjay, last changed 2017-04-15 00:17 by berker.peksag.

Pull Requests
URL Status Linked Edit
PR 879 merged python-dev, 2017-03-28 18:31
Messages (5)
msg290695 - (view) Author: Sanjay (Sanjay) * Date: 2017-03-28 10:37
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.
msg290700 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-28 12:31
Indeed, this looks as a bug.

>>> a < b
False
>>> b > a
True
msg290964 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-01 06:09
New changeset 7bd8d3e794782582a4ad1c9749424fff86802c3e by Serhiy Storchaka (s-sanjay) in branch 'master':
bpo-29931 fix __lt__ check in ipaddress.ip_interface for both v4 and v6. (#879)
https://github.com/python/cpython/commit/7bd8d3e794782582a4ad1c9749424fff86802c3e
msg291112 - (view) Author: Mariatta Wijaya (Mariatta) * (Python committer) Date: 2017-04-04 08:11
Serhiy, just checking whether this needs backport? The PR has the backport to 3.5 and 3.6 labels, but it's not indicated in this ticket.
If it doesn't need backport, then perhaps we can close this issue.
Thanks.
msg291684 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-15 00:16
I think we should backport this to at least 3.6.
History
Date User Action Args
2017-04-15 00:17:00berker.peksagsetnosy: + berker.peksag
messages: + msg291684
2017-04-04 08:54:03Mariattasetversions: + Python 3.5, Python 3.6
2017-04-04 08:32:51serhiy.storchakasetstage: needs patch -> backport needed
2017-04-04 08:11:11Mariattasetnosy: + Mariatta
messages: + msg291112
2017-04-01 06:09:55serhiy.storchakasetmessages: + msg290964
2017-03-28 18:31:20python-devsetpull_requests: + pull_request778
2017-03-28 12:31:47serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg290700
stage: needs patch
2017-03-28 10:37:20Sanjaycreate