From 7dacbec4f57bf491d2410518be0dc4636633d0f8 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Thu, 10 Sep 2026 12:12:40 -0700 Subject: [PATCH 1/3] gh-156680 - Update IPv4Network and IPv6Network docstring. Mention that the address argument can be a two-tuple representing address description and a netmask. --- Lib/ipaddress.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index de489c0ed034bb0..a2d2bc395b10d4c 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1567,6 +1567,13 @@ def __init__(self, address, strict=True): IPv4Interface(int(IPv4Interface('192.0.2.1'))) == IPv4Interface('192.0.2.1') + The address can also be a two-tuple of an address description + and a netmask, where the address description is either a + string, a 32-bits integer, a 4-bytes packed integer, or an + existing IPv4Address object; and the netmask is either an + integer representing the prefix length (e.g. 24) or a string + representing the prefix mask (e.g. '255.255.255.0'). + Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. NetmaskValueError: If the netmask isn't valid for @@ -2358,6 +2365,12 @@ def __init__(self, address, strict=True): IPv6Network(int(IPv6Network('2001:db8::'))) == IPv6Network('2001:db8::') + The address can also be a two-tuple of an address description + and a netmask, where the address description is either a + string, a 128-bits integer, a 16-bytes packed integer, or an + existing IPv6Address object; and the netmask is an integer + representing the prefix length. + strict: A boolean. If true, ensure that we have been passed A true network address, eg, 2001:db8::1000/124 and not an IP address on a network, eg, 2001:db8::1/124. From 31142fed0e12831aeb1eba122a0f7e8af490d770 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Thu, 10 Sep 2026 13:00:39 -0700 Subject: [PATCH 2/3] Update Lib/ipaddress.py Change to 32-bit integer and 4-byte packed integer. Co-authored-by: Stan Ulbrych --- Lib/ipaddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index a2d2bc395b10d4c..97b127daaeec5e6 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1569,7 +1569,7 @@ def __init__(self, address, strict=True): The address can also be a two-tuple of an address description and a netmask, where the address description is either a - string, a 32-bits integer, a 4-bytes packed integer, or an + string, a 32-bit integer, a 4-byte packed integer, or an existing IPv4Address object; and the netmask is either an integer representing the prefix length (e.g. 24) or a string representing the prefix mask (e.g. '255.255.255.0'). From 5a7c60221767213c2b9ecf5ef48d523433ef7c1b Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Thu, 10 Sep 2026 13:58:06 -0700 Subject: [PATCH 3/3] Fix the grammar and improve docstrings of the Network classes. --- Doc/library/ipaddress.rst | 14 +++++++------- Lib/ipaddress.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 387d8034bb8c84a..7d16357a9f33933 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -519,10 +519,10 @@ dictionaries. The interpretation is similar to an integer *address*. 4. A two-tuple of an address description and a netmask, where the address - description is either a string, a 32-bits integer, a 4-bytes packed - integer, or an existing :class:`IPv4Address` object; and the netmask is either - an integer representing the prefix length (e.g. ``24``) or a string - representing the prefix mask (e.g. ``255.255.255.0``). + description is either a string, a 32-bit integer, a 4-byte packed + integer, or an existing :class:`IPv4Address` object; and the netmask is + either an integer representing the prefix length (e.g. ``24``) or a + string representing the prefix mask (e.g. ``255.255.255.0``). An :exc:`AddressValueError` is raised if *address* is not a valid IPv4 address. A :exc:`NetmaskValueError` is raised if the mask is not valid for @@ -769,9 +769,9 @@ dictionaries. The interpretation is similar to an integer *address*. 4. A two-tuple of an address description and a netmask, where the address - description is either a string, a 128-bits integer, a 16-bytes packed - integer, or an existing :class:`IPv6Address` object; and the netmask is an - integer representing the prefix length. + description is either a string, a 128-bit integer, a 16-byte packed + integer, or an existing :class:`IPv6Address` object; and the netmask is + an integer representing the prefix length. An :exc:`AddressValueError` is raised if *address* is not a valid IPv6 address. A :exc:`NetmaskValueError` is raised if the mask is not valid for diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 97b127daaeec5e6..96a7fde75eb4d02 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1574,6 +1574,10 @@ def __init__(self, address, strict=True): integer representing the prefix length (e.g. 24) or a string representing the prefix mask (e.g. '255.255.255.0'). + strict: A boolean. If true, ensure that we have been passed + a true network address, eg, 192.0.2.0/24 and not an + IP address on a network, eg, 192.0.2.1/24. + Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. NetmaskValueError: If the netmask isn't valid for @@ -2365,14 +2369,14 @@ def __init__(self, address, strict=True): IPv6Network(int(IPv6Network('2001:db8::'))) == IPv6Network('2001:db8::') - The address can also be a two-tuple of an address description - and a netmask, where the address description is either a - string, a 128-bits integer, a 16-bytes packed integer, or an - existing IPv6Address object; and the netmask is an integer - representing the prefix length. + The address can also be a two-tuple of an address description and + a netmask, where the address description is either a string, a + 128-bit integer, a 16-byte packed integer, or an existing + IPv6Address object; and the netmask is an integer representing + the prefix length. strict: A boolean. If true, ensure that we have been passed - A true network address, eg, 2001:db8::1000/124 and not an + a true network address, eg, 2001:db8::1000/124 and not an IP address on a network, eg, 2001:db8::1/124. Raises: