Skip to content

Commit c3e97d9

Browse files
authored
bpo-30246: fix several error messages which only mention bytes in struct (#1421)
1 parent 1b8f612 commit c3e97d9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/_struct.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,8 @@ Struct___init___impl(PyStructObject *self, PyObject *format)
14531453
if (!PyBytes_Check(format)) {
14541454
Py_DECREF(format);
14551455
PyErr_Format(PyExc_TypeError,
1456-
"Struct() argument 1 must be a bytes object, not %.200s",
1456+
"Struct() argument 1 must be a str or bytes object, "
1457+
"not %.200s",
14571458
Py_TYPE(format)->tp_name);
14581459
return -1;
14591460
}
@@ -1535,7 +1536,7 @@ Struct_unpack_impl(PyStructObject *self, Py_buffer *buffer)
15351536
assert(self->s_codes != NULL);
15361537
if (buffer->len != self->s_size) {
15371538
PyErr_Format(StructError,
1538-
"unpack requires a bytes object of length %zd",
1539+
"unpack requires a buffer of %zd bytes",
15391540
self->s_size);
15401541
return NULL;
15411542
}
@@ -1708,8 +1709,8 @@ Struct_iter_unpack(PyStructObject *self, PyObject *buffer)
17081709
}
17091710
if (iter->buf.len % self->s_size != 0) {
17101711
PyErr_Format(StructError,
1711-
"iterative unpacking requires a bytes length "
1712-
"multiple of %zd",
1712+
"iterative unpacking requires a buffer of "
1713+
"a multiple of %zd bytes",
17131714
self->s_size);
17141715
Py_DECREF(iter);
17151716
return NULL;

0 commit comments

Comments
 (0)