Skip to content

ipaddress.IPv6Interface.ip drops the IPv6 scope ID #158723

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The ipaddress documentation, under IPv6Interface, says it implements the same attributes as IPv4Interface; the documented ip attribute is “An IPv4Address object with the address of the interface.” For IPv6Interface this is an IPv6Address object.

Expected: IPv6Address('fe80::1%eth0'), with scope_id 'eth0'

Actual: IPv6Address('fe80::1'), with scope_id None

import ipaddress as ip

s = 'fe80::1%eth0/0'
try:
    a, p = s.rsplit('/', 1)
    expected = ip.IPv6Address(a)
    if not 0 <= int(p) <= 128 or not expected.scope_id:
        raise ValueError('invalid prefix or missing scope')
    actual = ip.IPv6Interface(s).ip
    if actual != expected or actual.scope_id != expected.scope_id:
        print(f'REFUTATION CONFIRMED: {s!r} actual: {actual!r} expected: {expected!r}')
    else:
        print('REFUTATION REJECTED: actual matches the scoped address')
except ValueError as e:
    print(f'REFUTATION REJECTED: invalid input: {e}')

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

REFUTATION CONFIRMED: 'fe80::1%eth0/0' actual: IPv6Address('fe80::1') expected: IPv6Address('fe80::1%eth0')

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-050858-c2

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