https://github.com/python/cpython/commit/deb0020e3d478fa72104b82e2ba1a1c0c6eb4eae commit: deb0020e3d478fa72104b82e2ba1a1c0c6eb4eae branch: main author: AN Long <a...@users.noreply.github.com> committer: encukou <encu...@gmail.com> date: 2025-08-11T15:04:47+02:00 summary:
gh-115766: Fix IPv4Interface.is_unspecified (GH-137326) files: A Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst M Lib/ipaddress.py M Lib/test/test_ipaddress.py 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..d8d2203847caf6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-03-00-36-57.gh-issue-115766.nJCFkW.rst @@ -0,0 +1 @@ +Fix :attr:`!ipaddress.IPv4Interface.is_unspecified`. _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: arch...@mail-archive.com