From 8cdbdf347a5f79bfc5e72288d336feceeff6a9d8 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 3 Aug 2025 00:37:05 +0900 Subject: [PATCH 1/3] Fix IPv4Interface.is_unspecified --- Lib/ipaddress.py | 4 ++++ Lib/test/test_ipaddress.py | 4 ++++ .../Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst | 1 + 3 files changed, 9 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 8b60b9d5c9cd51..7470dc6c52d3a8 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1479,6 +1479,10 @@ def with_hostmask(self): return '%s/%s' % (self._string_from_ip_int(self._ip), self.hostmask) + @property + def is_unspecified(self): + return self._ip == 0 and self.network.is_unspecified + class IPv4Network(_BaseV4, _BaseNetwork): diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index db1c38243e2268..62929f9dd68b5a 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -2269,6 +2269,10 @@ def testReservedIpv4(self): self.assertEqual(False, ipaddress.ip_network('240.0.0.0').is_multicast) self.assertEqual(True, ipaddress.ip_network('240.0.0.0').is_reserved) + self.assertTrue(ipaddress.ip_interface('0.0.0.0/32').is_unspecified) + self.assertFalse(ipaddress.ip_interface('0.0.0.0/31').is_unspecified) + self.assertFalse(ipaddress.ip_interface('1.2.3.4/32').is_unspecified) + self.assertEqual(True, ipaddress.ip_interface( '192.168.1.1/17').is_private) self.assertEqual(False, ipaddress.ip_network('192.169.0.0').is_private) diff --git a/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst new file mode 100644 index 00000000000000..000c1381ed0fb2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst @@ -0,0 +1 @@ +Fix :meth:`ipaddress.IPv4Interface.is_unspecified`. From 6011389593b6ef52c3e18806f88a10dd01cf17f3 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 3 Aug 2025 00:43:58 +0900 Subject: [PATCH 2/3] Fix sphinx marker --- .../next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst index 000c1381ed0fb2..69c3a57e39b261 100644 --- a/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst +++ b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst @@ -1 +1 @@ -Fix :meth:`ipaddress.IPv4Interface.is_unspecified`. +Fix :attr:`ipaddress.IPv4Interface.is_unspecified`. From 14b2e5af83c440b3409fce7ecb286770805ee4e8 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 3 Aug 2025 01:03:01 +0900 Subject: [PATCH 3/3] Fix rst marker --- .../next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst index 69c3a57e39b261..d8d2203847caf6 100644 --- a/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst +++ b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst @@ -1 +1 @@ -Fix :attr:`ipaddress.IPv4Interface.is_unspecified`. +Fix :attr:`!ipaddress.IPv4Interface.is_unspecified`.