Skip to content

Commit e9745c3

Browse files
committed
Address review comments
Finish the next_network() docstring: a period on the argument sentence and a Raises section for the two ValueError cases. Build the result from an (address, prefix) tuple rather than formatting and reparsing a string. Give the What's New and NEWS entries explicit link titles so the IPv4Network and IPv6Network methods no longer both render as next_network().
1 parent 43884d5 commit e9745c3

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

Doc/whatsnew/3.16.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ io
412412
ipaddress
413413
---------
414414

415-
* Add :meth:`~ipaddress.IPv4Network.next_network` and
416-
:meth:`~ipaddress.IPv6Network.next_network` methods to find the next nearest
417-
network with a specific prefix size.
415+
* Add :meth:`IPv4Network.next_network() <ipaddress.IPv4Network.next_network>`
416+
and :meth:`IPv6Network.next_network() <ipaddress.IPv6Network.next_network>`
417+
methods to find the next nearest network with a specific prefix size.
418418
(Contributed by Faisal Mahmood in :gh:`87027`.)
419419

420420

Lib/ipaddress.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,15 @@ def next_network(self, next_prefix=None):
11241124
11251125
Args:
11261126
next_prefix: The desired next prefix length, if not specified the
1127-
same self.prefixlen will be used
1127+
same self.prefixlen will be used.
11281128
11291129
Returns:
11301130
An IPv(4|6) Network object of the next closest network.
11311131
1132+
Raises:
1133+
ValueError: If next_prefix is outside the range of valid prefix
1134+
lengths, or if no further network of that size exists.
1135+
11321136
"""
11331137
if next_prefix is None:
11341138
next_prefix = self.prefixlen
@@ -1156,9 +1160,7 @@ def next_network(self, next_prefix=None):
11561160
"network"
11571161
)
11581162

1159-
return self.__class__(
1160-
f"{self._string_from_ip_int(next_ip)}/{next_prefix}"
1161-
)
1163+
return self.__class__((next_ip, next_prefix))
11621164

11631165

11641166
class _BaseConstants:
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Add :meth:`~ipaddress.IPv4Network.next_network` and
2-
:meth:`~ipaddress.IPv6Network.next_network`. Patch by Faisal Mahmood.
1+
Add :meth:`IPv4Network.next_network() <ipaddress.IPv4Network.next_network>`
2+
and :meth:`IPv6Network.next_network() <ipaddress.IPv6Network.next_network>`.
3+
Patch by Faisal Mahmood.

0 commit comments

Comments
 (0)