From 28dc1186a895ee76cbe039d71110b8a31fa1add4 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 11 Jun 2016 22:30:05 +0300 Subject: Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__ Patch by Gareth Rees. --- Lib/ipaddress.py | 4 ++-- Lib/test/test_ipaddress.py | 1 + Misc/NEWS | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 1f90058..20f33cb 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -636,12 +636,12 @@ class _BaseNetwork(_IPAddressBase): broadcast = int(self.broadcast_address) if n >= 0: if network + n > broadcast: - raise IndexError + raise IndexError('address out of range') return self._address_class(network + n) else: n += 1 if broadcast + n < network: - raise IndexError + raise IndexError('address out of range') return self._address_class(broadcast + n) def __lt__(self, other): diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index be62fad..6c08f80 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -1176,6 +1176,7 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(str(self.ipv6_network[5]), '2001:658:22a:cafe::5') + self.assertRaises(IndexError, self.ipv6_network.__getitem__, 1 << 64) def testGetitem(self): # http://code.google.com/p/ipaddr-py/issues/detail?id=15 diff --git a/Misc/NEWS b/Misc/NEWS index 8c85c21b..acf1a2e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -38,6 +38,9 @@ Core and Builtins Library ------- +- Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__. + Patch by Gareth Rees. + - Issue #21386: Implement missing IPv4Address.is_global property. It was documented since 07a5610bae9d. Initial patch by Roger Luethi. -- cgit v0.12