New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexError from ipaddress._BaseNetwork.__getitem__ has no message #64707
Comments
If you try to look up an out-of-range address from an object returned Python 3.4.0b3 (default, Jan 27 2014, 02:26:41)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>> ipaddress.ip_network('2001:db8::8/125')[100]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/ipaddress.py", line 601, in __getitem__
raise IndexError
IndexError Normally an IndexError is associated with a message explaining the >>> [].pop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: pop from empty list It would be nice if the IndexError from With the attached patch, the error message looks like this in the >>> ipaddress.ip_network('2001:db8::8/125')[100]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/gdr/hg.python.org/cpython/Lib/ipaddress.py", line 602, in __getitem__
% (self, self.num_addresses))
IndexError: 100 out of range 0..7 for 2001:db8::8/125 and like this in the negative case: >>> ipaddress.ip_network('2001:db8::8/125')[-100]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/gdr/hg.python.org/cpython/Lib/ipaddress.py", line 608, in __getitem__
% (n - 1, self.num_addresses, self))
IndexError: -100 out of range -8..-1 for 2001:db8::8/125 (If you have a better suggestion for how the error message should |
Could someone review the attached patch please. I've looked at the test code and there is one assertRaises for IndexError which I'm assuming covers this case. |
+1 for "address index out of range". The current test only covers the first IndexError. We also need to add another one for the else branch. |
I've attached a revised patch that addresses Berker Peksag's concerns:
|
Thank you Gareth. I will commit ipaddress.patch this weekend. |
New changeset bc758c62bc4f by Berker Peksag in branch 'default': |
Thank you for applying this patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: