Title: Improvements to ipaddress module
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, 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-04-15 23:37 by inada.naoki.

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
Messages (8)
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)
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.

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)
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("").
Date User Action Args
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