https://github.com/python/cpython/commit/0e1ae61f7115db4c91dccc5fd9d7b8c801ef0b59 commit: 0e1ae61f7115db4c91dccc5fd9d7b8c801ef0b59 branch: main author: Senthil Kumaran <[email protected]> committer: orsenthil <[email protected]> date: 2026-09-18T19:06:08Z summary:
gh-156680 - Update IPv4Network and IPv6Network docstring. (#157280) Update IPv4Network and IPv6Network docstring. Mention that the address argument can be a two-tuple representing address description and a netmask. Co-authored-by: Stan Ulbrych <[email protected]> files: M Doc/library/ipaddress.rst M Lib/ipaddress.py 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 de489c0ed034bb0..f160cc6a7ce900e 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1567,6 +1567,17 @@ 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-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'). + + strict: A boolean. If true, ensure that we have been passed + a true network address, for example, 192.0.2.0/24 and not an + IP address on a network, for example, 192.0.2.1/24. + Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. NetmaskValueError: If the netmask isn't valid for @@ -2358,9 +2369,15 @@ 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-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 - IP address on a network, eg, 2001:db8::1/124. + a true network address, for example, 2001:db8::1000/124 and not an + IP address on a network, for example, 2001:db8::1/124. Raises: AddressValueError: If address isn't a valid IPv6 address. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
