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.

classification
Title: ipaddress: Add optional prefixlen argument to ip_interface and ip_network
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Gary.van.der.Merwe, Ilya.Kulakov, ncoghlan, pmoody
Priority: normal Keywords:

Created on 2014-11-28 08:54 by Gary.van.der.Merwe, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg231800 - (view) Author: Gary van der Merwe (Gary.van.der.Merwe) Date: 2014-11-28 08:54
Currently if one has an ip address in int or IPv4Address/IPv6Address form, it is not possilbe to create a ip_interface or ip_network from that with specific prefix length, without first converting the address into string form, and then appending the prefixlen 

Please could an optional prefixlen argument to ip_interface and ip_network (and the __init__ functions for their backing classes) so that one can do this.

e.g: it should work like this:

>>> ipaddress.ip_interface(167772161, prefixlen=24)
IPv4Interface('10.0.0.1/24')

I would like to do a patch for this. I would just first like some feedback as to whether a patch for this would accepted.
msg290061 - (view) Author: Ilya Kulakov (Ilya.Kulakov) * Date: 2017-03-23 21:56
You can initialize ip_interface via a tuple of 2 elements: IP address and a prefix (prefixlen or string representation of a netmask).

I believe the issue can be closed now.
msg290522 - (view) Author: Gary van der Merwe (Gary.van.der.Merwe) Date: 2017-03-26 10:30
Indeed. Thanks to whoever fixed this.
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67151
2017-03-26 10:30:02Gary.van.der.Merwesetstatus: open -> closed
resolution: fixed
messages: + msg290522

stage: resolved
2017-03-23 21:56:13Ilya.Kulakovsetnosy: + Ilya.Kulakov
messages: + msg290061
2014-11-28 21:01:23berker.peksagsetnosy: + ncoghlan, pmoody

versions: + Python 3.5
2014-11-28 08:54:06Gary.van.der.Merwecreate