Skip to content

IPv6Network.address_exclude raises AssertionError for contained scoped IPv6 networks #158727

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: "Computes the network definitions resulting from removing the given network from this one. Returns an iterator of network objects. Raises ValueError if other is not completely contained in self." — ipaddress documentation, IPv6Network.address_exclude.

Expected: Complete successfully with networks covering exactly fe80::1 through fe80::3.

Actual: AssertionError: Error performing exclusion: s1: fe80::/127 s2: fe80::2/127 other: fe80::%a/128

import ipaddress

inputs = ('fe80::%a/126', 'fe80::%a/128')
try:
    n, other = map(ipaddress.IPv6Network, inputs)
    if not other.subnet_of(n):
        raise ValueError("other is not completely contained in n")
    expected = list(range(int(n.network_address) + 1,
                          int(n.network_address) + n.num_addresses))
except Exception as e:
    print("REFUTATION REJECTED:", inputs, "invalid input:", repr(e))
else:
    try:
        result = list(n.address_exclude(other))
        actual = {
            "networks": list(map(str, result)),
            "addresses": sorted(
                a for net in result
                for a in range(int(net.network_address),
                               int(net.network_address) + net.num_addresses)
            ),
        }
        broken = actual["addresses"] != expected
    except Exception as e:
        actual = {"exception": type(e).__name__, "message": str(e)}
        broken = True
    if broken:
        print("REFUTATION CONFIRMED:", inputs, "actual =", actual,
              "expected =", expected)
    else:
        print("REFUTATION REJECTED:", inputs,
              "exclusion completed with exactly the expected coverage")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library ipaddress:

REFUTATION CONFIRMED: ('fe80::%a/126', 'fe80::%a/128') actual = {'exception': 'AssertionError', 'message': 'Error performing exclusion: s1: fe80::/127 s2: fe80::2/127 other: fe80::%a/128'} expected = [338288524927261089654018896841347694593, 338288524927261089654018896841347694594, 338288524927261089654018896841347694595]

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/ipaddress-20261003-235502-c3

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions