dtoolutil: Improve error messages for iostream wrappers

This commit is contained in:
rdb 2025-12-30 23:18:46 +01:00
parent 52829ed610
commit b4b18724bd
1 changed files with 6 additions and 3 deletions

View File

@ -134,8 +134,9 @@ readinto(PyObject *b) {
Py_buffer view;
if (PyObject_GetBuffer(b, &view, PyBUF_CONTIG) == -1) {
PyErr_SetString(PyExc_TypeError,
"write() requires a contiguous, read-write bytes-like object");
PyErr_Format(PyExc_TypeError,
"readinto() requires a contiguous, read-write bytes-like object, not '%.100s'",
Py_TYPE(b)->tp_name);
return 0;
}
@ -260,7 +261,9 @@ write(PyObject *b) {
Py_buffer view;
if (PyObject_GetBuffer(b, &view, PyBUF_CONTIG_RO) == -1) {
PyErr_SetString(PyExc_TypeError, "write() requires a contiguous buffer");
PyErr_Format(PyExc_TypeError,
"write() requires a bytes-like object, not '%.100s'",
Py_TYPE(b)->tp_name);
return;
}