Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28dc118

Browse files
committed
Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__
Patch by Gareth Rees.
1 parent 24b102e commit 28dc118

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/ipaddress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,12 @@ def __getitem__(self, n):
636636
broadcast = int(self.broadcast_address)
637637
if n >= 0:
638638
if network + n > broadcast:
639-
raise IndexError
639+
raise IndexError('address out of range')
640640
return self._address_class(network + n)
641641
else:
642642
n += 1
643643
if broadcast + n < network:
644-
raise IndexError
644+
raise IndexError('address out of range')
645645
return self._address_class(broadcast + n)
646646

647647
def __lt__(self, other):

Lib/test/test_ipaddress.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ def testNth(self):
11761176

11771177
self.assertEqual(str(self.ipv6_network[5]),
11781178
'2001:658:22a:cafe::5')
1179+
self.assertRaises(IndexError, self.ipv6_network.__getitem__, 1 << 64)
11791180

11801181
def testGetitem(self):
11811182
# http://code.google.com/p/ipaddr-py/issues/detail?id=15

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Core and Builtins
3838
Library
3939
-------
4040

41+
- Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__.
42+
Patch by Gareth Rees.
43+
4144
- Issue #21386: Implement missing IPv4Address.is_global property. It was
4245
documented since 07a5610bae9d. Initial patch by Roger Luethi.
4346

0 commit comments

Comments
 (0)