Skip to content

Commit

Permalink
pythongh-127740: Improve error messages as suggested by @hauntsaninja
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasreddy committed Dec 10, 2024
1 parent 7c819c1 commit 862bfd5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ def test_fromhex(self):
self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34')

# For odd number of character(s)
for value in ("a", "a ", " a"," a ", "aaa", "aaa ", " aaa", " aaa ", " aa a "):
for value in ("a", "a ", " a"," a ", "aaa", "aaa ", " aaa", " aaa "):
with self.assertRaises(ValueError) as cm:
self.type2test.fromhex(value)
self.assertIn("fromhex() arg must be of even length", str(cm.exception))
self.assertIn("fromhex() arg must contain an even number of hexadecimal digits", str(cm.exception))

for data, pos in (
# invalid first hexadecimal character
Expand Down
2 changes: 1 addition & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
error:
if (invalid_char == -1) {
PyErr_SetString(PyExc_ValueError,
"fromhex() arg must be of even length");
"fromhex() arg must contain an even number of hexadecimal digits");
} else {
PyErr_Format(PyExc_ValueError,
"non-hexadecimal number found in "
Expand Down

0 comments on commit 862bfd5

Please sign in to comment.