Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for invalid type in bytes.fromhex()
  • Loading branch information
lordmauve committed Mar 12, 2025
commit f859c3c28d8583310f149794c630de86788fd7df
5 changes: 5 additions & 0 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ def test_fromhex(self):
self.assertRaises(ValueError, self.type2test.fromhex, b)

self.assertEqual(self.type2test.fromhex('0000'), b'\0\0')
with self.assertRaisesRegex(
TypeError,
r'fromhex\(\) argument must be str or bytes-like, not tuple',
):
self.type2test.fromhex(())
self.assertRaises(ValueError, self.type2test.fromhex, 'a')
self.assertRaises(ValueError, self.type2test.fromhex, 'rt')
self.assertRaises(ValueError, self.type2test.fromhex, '1a b cd')
Expand Down
2 changes: 1 addition & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
}
else {
PyErr_Format(PyExc_TypeError,
"fromhex() argument must be str or bytes, not %T",
"fromhex() argument must be str or bytes-like, not %T",
string);
return NULL;
}
Comment thread
lordmauve marked this conversation as resolved.
Expand Down