This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2016-08-25 15:14 by moritzs, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
ipaddress-improvement.patch moritzs, 2016-08-25 15:14 review
Pull Requests
URL Status Linked Edit
PR 12774 closed methane, 2019-04-11 06:24
PR 12832 merged methane, 2019-04-15 06:21
PR 12836 merged methane, 2019-04-15 10:47
PR 14200 merged methane, 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 (methane) * (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 (methane) * (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 (methane) * (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 (methane) * (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 (methane) * (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("").
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 (methane) * (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 (methane) * (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 (methane) * (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)
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72047
2019-06-19 11:48:12methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-06-19 11:47:45methanesetmessages: + msg346038
2019-06-18 12:20:55methanesetpull_requests: + pull_request14038
2019-06-18 12:16:41methanesetmessages: + msg345983
2019-05-27 19:10:40berker.peksagsetnosy: - berker.peksag
2019-05-27 19:04:57Jacktosesetmessages: + msg343671
2019-05-26 08:02:16methanesetmessages: + 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:38methanesetmessages: + msg340308
2019-04-15 23:32:37methanesetmessages: + msg340307
2019-04-15 10:59:18methanesetmessages: + msg340259
versions: + Python 3.8, - Python 3.7
2019-04-15 10:47:38methanesetpull_requests: + pull_request12761
2019-04-15 07:01:06methanesetmessages: + msg340240
2019-04-15 06:21:39methanesetpull_requests: + pull_request12757
2019-04-11 06:24:50methanesetpull_requests: + pull_request12701
2019-04-10 10:32:12methanesetnosy: + methane
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