Issue 26457: Error in ipaddress.address_exclude function (original) (raw)

Created on 2016-02-29 06:29 by out, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
address_exclude.patch xiang.zhang,2016-03-01 07:19 ipaddress._BaseNetwork.subnets include broadcast network review
Messages (5)
msg260994 - (view) Author: feng liang (out) Date: 2016-02-29 06:29
when i read in document 3.5.1,run the example in ipaddress.address_exclude function >>> n1 = ip_network('192.0.2.0/28') >>> n2 = ip_network('192.0.2.1/32') >>> list(n1.address_exclude(n2)) I got: Traceback (most recent call last): File "", line 1, in File "C:\Python 3.5\lib\ipaddress.py", line 794, in address_exclude s1, s2 = s1.subnets() ValueError: not enough values to unpack (expected 2, got 1)
msg261037 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-03-01 03:22
In old ipaddr.py, IPv4Network('192.0.2.0/31').subnet() returns [IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.1/32')], but ipaddress returns only [IPv4Network('192.0.2.0/32')]. It seems simply change end to end+1 in https://hg.python.org/cpython/file/tip/Lib/ipaddress.py#l921 can solve the problem and pass the test. But maybe there are some side effects.
msg261041 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-03-01 07:19
I propose a patch simply add one to end so that the broadcast address network will appear in the result, which behaves the same as ipaddr.py. Corresponding tests are added. All tests are passed but I am afraid some logic may break.
msg261042 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-01 08:21
LGTM. I have wrote similar patch but with different tests.
msg261043 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-01 08:26
New changeset 6d6c0a7b71f5 by Serhiy Storchaka in branch '3.5': Issue #26457: Fixed the subnets() methods in IP network classes for the case https://hg.python.org/cpython/rev/6d6c0a7b71f5 New changeset c092148a1b55 by Serhiy Storchaka in branch 'default': Issue #26457: Fixed the subnets() methods in IP network classes for the case https://hg.python.org/cpython/rev/c092148a1b55
History
Date User Action Args
2022-04-11 14:58:28 admin set github: 70644
2016-03-01 08:26:58 serhiy.storchaka set status: open -> closedresolution: fixedstage: commit review -> resolved
2016-03-01 08:26:32 python-dev set nosy: + python-devmessages: +
2016-03-01 08:21:13 serhiy.storchaka set assignee: serhiy.storchakastage: needs patch -> commit reviewmessages: + versions: + Python 3.6
2016-03-01 07:19:14 xiang.zhang set files: + address_exclude.patchkeywords: + patchmessages: +
2016-03-01 06:19:58 serhiy.storchaka set nosy: + serhiy.storchakastage: needs patch
2016-03-01 03:22:09 xiang.zhang set messages: +
2016-02-29 07:23:34 serhiy.storchaka set nosy: + ncoghlan, pmoody
2016-02-29 06:42:51 xiang.zhang set nosy: + xiang.zhang
2016-02-29 06:29:44 out create