Skip to content
Open
4 changes: 3 additions & 1 deletion Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,7 @@ def __init__(self, address):
self.network = IPv6Network((addr, mask), strict=False)
self.netmask = self.network.netmask
self._prefixlen = self.network._prefixlen
self._scope_id = addr.scope_id if isinstance(addr, IPv6Address) else None

@functools.cached_property
def hostmask(self):
Expand Down Expand Up @@ -2239,7 +2240,8 @@ def __hash__(self):

@property
def ip(self):
return IPv6Address(self._ip)
addr_str = self._string_from_ip_int(self._ip) + (f'%{self._scope_id}' if self._scope_id else '')
return IPv6Address(addr_str)

@property
def with_prefixlen(self):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ def test_copy(self):
self.assertEqual(addr, copy.copy(addr))
self.assertEqual(addr, copy.deepcopy(addr))

# issue: 129538
def test_ipv6_interface_scope_id(self):
addr = ipaddress.IPv6Address("fe80::%10")
addr_with_prefix = ipaddress.IPv6Interface((addr, 64))
self.assertEqual(addr_with_prefix.ip, ipaddress.IPv6Address("fe80::%10"))


class NetmaskTestMixin_v4(CommonTestMixin_v4):
"""Input validation on interfaces and networks is very similar"""
Expand Down
Loading