Skip to content

IPv6Network.next_network() raises the wrong error when addresses run out #156680

Description

@fedonman

Bug description:

_BaseNetwork.next_network() guards address-space exhaustion with except OverflowError, which only the IPv4 path raises, so on IPv6 the internal ValueError from _string_from_ip_int() escapes instead.

from ipaddress import IPv4Network, IPv6Network

for net in (IPv4Network('255.255.255.0/24'),
            IPv6Network('ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112')):
    try:
        net.next_network()
    except ValueError as e:
        print(f"{net}: {e}")

Output:

255.255.255.0/24: out of address space, cannot make another /24 network
ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112: IPv6 address is too large

Expected: out of address space, cannot make another /112 network, the message Doc/library/ipaddress.rst gives for next_network().

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions