https://github.com/python/cpython/commit/6e6e83eb0da240e618806b3ded86e817dcaa4f18
commit: 6e6e83eb0da240e618806b3ded86e817dcaa4f18
branch: main
author: Gregory P. Smith <[email protected]>
committer: gpshead <[email protected]>
date: 2026-11-01T20:36:11Z
summary:
gh-161100: Fix `IPv6Interface.is_unspecified` for IPv4-mapped addresses
(GH-161101)
Defer to IPv6Address.is_unspecified, as the is_loopback override does,
so ::ffff:0.0.0.0/128 interfaces are unspecified like the address.
ANT-2026-DIFE27WF
files:
A Misc/NEWS.d/next/Library/2026-10-22-05-20-06.gh-issue-161100.pLgnlA.rst
M Lib/ipaddress.py
M Lib/test/test_ipaddress.py
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index 8ac2a537c46dee..b11999a0f44bcc 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -2326,7 +2326,7 @@ def with_hostmask(self):
@property
def is_unspecified(self):
- return self._ip == 0 and self.network.is_unspecified
+ return super().is_unspecified and self.network.is_unspecified
@property
def is_loopback(self):
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
index 758774effc183c..9110124d9423cf 100644
--- a/Lib/test/test_ipaddress.py
+++ b/Lib/test/test_ipaddress.py
@@ -2495,6 +2495,14 @@ def testReservedIpv6(self):
self.assertEqual(False, ipaddress.ip_network('::1').is_unspecified)
self.assertEqual(False, ipaddress.ip_network('::/127').is_unspecified)
+ self.assertTrue(ipaddress.ip_interface('::/128').is_unspecified)
+ self.assertTrue(
+ ipaddress.ip_interface('::ffff:0.0.0.0/128').is_unspecified)
+ self.assertFalse(ipaddress.ip_interface('::/127').is_unspecified)
+ self.assertFalse(
+ ipaddress.ip_interface('::ffff:0.0.0.0/127').is_unspecified)
+ self.assertFalse(ipaddress.ip_interface('::1/128').is_unspecified)
+
self.assertEqual(True,
ipaddress.ip_network('2001::1/128').is_private)
self.assertEqual(True,
@@ -2588,6 +2596,17 @@ def testIpv4MappedProperties(self):
self.assertEqual(ipv4.is_link_local, ipv6.is_link_local)
self.assertEqual(ipv4.is_loopback, ipv6.is_loopback)
+ ipv4 = ipaddress.IPv4Interface(addr4)
+ ipv6 = ipaddress.IPv6Interface(f"::ffff:{addr4}")
+
+ self.assertEqual(ipv4.is_global, ipv6.is_global)
+ self.assertEqual(ipv4.is_private, ipv6.is_private)
+ self.assertEqual(ipv4.is_reserved, ipv6.is_reserved)
+ self.assertEqual(ipv4.is_multicast, ipv6.is_multicast)
+ self.assertEqual(ipv4.is_unspecified, ipv6.is_unspecified)
+ self.assertEqual(ipv4.is_link_local, ipv6.is_link_local)
+ self.assertEqual(ipv4.is_loopback, ipv6.is_loopback)
+
def testIpv4MappedPrivateCheck(self):
self.assertEqual(
True, ipaddress.ip_address('::ffff:192.168.1.1').is_private)
diff --git
a/Misc/NEWS.d/next/Library/2026-10-22-05-20-06.gh-issue-161100.pLgnlA.rst
b/Misc/NEWS.d/next/Library/2026-10-22-05-20-06.gh-issue-161100.pLgnlA.rst
new file mode 100644
index 00000000000000..b23de8a22ca968
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-10-22-05-20-06.gh-issue-161100.pLgnlA.rst
@@ -0,0 +1,3 @@
+Fix :attr:`!ipaddress.IPv6Interface.is_unspecified` returning ``False`` for
+the IPv4-mapped address ``::ffff:0.0.0.0``. It now gives the same result as
+:attr:`ipaddress.IPv6Address.is_unspecified`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]