classification
Title: Improvements to ipaddress module
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jacktose, SilentGhost, inada.naoki, moritzs, ncoghlan, pmoody, serhiy.storchaka, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-08-25 15:14 by moritzs, last changed 2019-06-19 11:48 by inada.naoki. This issue is now closed.

Files
File name Uploaded Description Edit
ipaddress-improvement.patch moritzs, 2016-08-25 15:14 review
Pull Requests
URL Status Linked Edit
PR 12774 closed inada.naoki, 2019-04-11 06:24
PR 12832 merged inada.naoki, 2019-04-15 06:21
PR 12836 merged inada.naoki, 2019-04-15 10:47
PR 14200 merged inada.naoki, 2019-06-18 12:20
Messages (13)
msg273655 - (view) Author: Moritz Sichert (moritzs) * Date: 2016-08-25 15:14
This patch fixes the following minor issues with the ipaddress module:

- Removed unused property _BaseV4._valid_mask_octets
- Removed unused methods _BaseV4._is_valid_netmask() and _BaseV4._is_hostmask()
- Replaced several calls to superclass constructors by super()

It also refactors the constructors of IPv4Network, IPv4Interface, IPv6Network, and IPv6Interface.
They all now use the new method _get_addr_prefix_tuple() to parse the argument. It now matches the following sentence of the documentation of IPv4/6Interface:
"The meaning of address is as in the constructor of IPv4Network".

Additionally they now also accept a bytes or an IPv4/6Address object representing a netmask (or a hostmask [only IPv4]) as second element of an address/netmask tuple. This makes it easier to work with C-APIs that provide netmasks only as bytes object.

This patch does not try to solve issue 27683.
msg279600 - (view) Author: Moritz Sichert (moritzs) * Date: 2016-10-28 12:46
Any updates?
msg279607 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2016-10-28 14:27
Peter, are you able to take a look at this or indicate you're happy for someone else to take it? (I relinquished my co-maintainer role for the ipaddress module a while back, so you're the only currently listed maintainer)
msg339845 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-10 10:32
@moritzs  Would you create a pull request on GitHub?
Or may I create a pull request for your patch?
msg340240 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-15 07:01
New changeset 2430d532e240dea55f0082d1e9bf2e0f3d7505be by Inada Naoki in branch 'master':
bpo-27860: use cached_property (GH-12832)
https://github.com/python/cpython/commit/2430d532e240dea55f0082d1e9bf2e0f3d7505be
msg340259 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-15 10:59
I am not owner of ipaddress module, so I don't know we should
support more form of masks.

On the other hand, IPv4Interface and IPv6Interface expose
netmask and hostmask attributes when address is not bytes or int.

These attributes are not documented.  I assume it was added
accidentally, when coping some code from Network classes.

But there are test for these attributes.
NetmaskTestMixin_v4.test_valid_netmask runs for IPv4Network and IPv4Interface.
It checks these attributes when constructor argument is string.
https://github.com/python/cpython/blob/3c7931e514faf509a39c218c2c9f55efb434628f/Lib/test/test_ipaddress.py#L422-L440

For safety, I added these attributes always, instead of remove them.

PR-12836 is fixing it, and extracts methods for Network/Interface constructor
(a part of PR-12774).  It doesn't add additional mask form support.
msg340307 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-15 23:32
New changeset 6fa84bd12c4b83bee6a41b989363230d5c03b96c by Inada Naoki in branch 'master':
bpo-27860: ipaddress: fix Interface missed some attributes (GH-12836)
https://github.com/python/cpython/commit/6fa84bd12c4b83bee6a41b989363230d5c03b96c
msg340308 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-15 23:37
I merged all cleanups.

I don't merge accepting any IP representations as mask, because I'm not expert of this module.
At least, I don't want to pass prefix/netmask by something like IPv4Network("0.0.255.255").
msg343349 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-05-24 08:06
I was wondering why it was decided against backporting to 3.7? 6fa84bd12c4b83bee6a41b989363230d5c03b96c fixes an actual bug #35990 (string mask in tuple argument for IPv4Interfaces). Incidentally, there are also no tests for this behaviour.

Just to note: both merged PRs lacked news entry.
msg343537 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-05-26 08:02
> I was wondering why it was decided against backporting to 3.7?

Because I treats this is just a code cleanup.

> 6fa84bd12c4b83bee6a41b989363230d5c03b96c fixes an actual bug #35990 (string mask in tuple argument for IPv4Interfaces).

I didn't thought it was a bug.
I don't know it is real bug which should be backported to 3.7 for now.

> Incidentally, there are also no tests for this behavior.

Because I thought there are no change about public (documented) behavior.

> Just to note: both merged PRs lacked news entry.

NEWS entry is not needed for code cleanup.
msg343671 - (view) Author: Jack (Jacktose) Date: 2019-05-27 19:04
I for one have encountered #35990 in my work and would appreciate a backport.
msg345983 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-06-18 12:16
OK, I thought I improved only undocumented behavior, but it was documented and previous behavior didn't follow the document.
I'll backport PR 12836.
msg346038 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-06-19 11:47
New changeset f532fe5583d29d21e12aa22d8fca13e3bca94fb3 by Inada Naoki in branch '3.7':
bpo-27860: ipaddress: fix Interface constructor (GH-14200)
https://github.com/python/cpython/commit/f532fe5583d29d21e12aa22d8fca13e3bca94fb3
History
Date User Action Args
2019-06-19 11:48:12inada.naokisetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-06-19 11:47:45inada.naokisetmessages: + msg346038
2019-06-18 12:20:55inada.naokisetpull_requests: + pull_request14038
2019-06-18 12:16:41inada.naokisetmessages: + msg345983
2019-05-27 19:10:40berker.peksagsetnosy: - berker.peksag
2019-05-27 19:04:57Jacktosesetmessages: + msg343671
2019-05-26 08:02:16inada.naokisetmessages: + msg343537
2019-05-24 17:29:52Jacktosesetnosy: + Jacktose
2019-05-24 08:06:10SilentGhostsetnosy: + SilentGhost

messages: + msg343349
versions: + Python 3.7
2019-05-24 08:00:30SilentGhostlinkissue35990 superseder
2019-04-15 23:37:38inada.naokisetmessages: + msg340308
2019-04-15 23:32:37inada.naokisetmessages: + msg340307
2019-04-15 10:59:18inada.naokisetmessages: + msg340259
versions: + Python 3.8, - Python 3.7
2019-04-15 10:47:38inada.naokisetpull_requests: + pull_request12761
2019-04-15 07:01:06inada.naokisetmessages: + msg340240
2019-04-15 06:21:39inada.naokisetpull_requests: + pull_request12757
2019-04-11 06:24:50inada.naokisetpull_requests: + pull_request12701
2019-04-10 10:32:12inada.naokisetnosy: + inada.naoki
messages: + msg339845
2016-11-07 13:46:49berker.peksagsetnosy: + berker.peksag
2016-10-28 14:44:12serhiy.storchakasetversions: + Python 3.7, - Python 3.6
2016-10-28 14:27:51ncoghlansetmessages: + msg279607
2016-10-28 12:46:46moritzssetmessages: + msg279600
2016-08-26 02:47:28xiang.zhangsetnosy: + xiang.zhang
2016-08-25 16:26:52serhiy.storchakasetnosy: + ncoghlan, serhiy.storchaka
2016-08-25 16:13:56SilentGhostsetnosy: + pmoody

stage: patch review
2016-08-25 15:14:28moritzscreate