Skip to content

bpo-30246: fix several error messages which only mention bytes in struct #1421

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

Merged
merged 3 commits into from
Sep 14, 2017
Merged
Changes from all commits
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
9 changes: 5 additions & 4 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,8 @@ Struct___init___impl(PyStructObject *self, PyObject *format)
if (!PyBytes_Check(format)) {
Py_DECREF(format);
PyErr_Format(PyExc_TypeError,
"Struct() argument 1 must be a bytes object, not %.200s",
"Struct() argument 1 must be a str or bytes object, "
"not %.200s",
Py_TYPE(format)->tp_name);
return -1;
}
Expand Down Expand Up @@ -1563,7 +1564,7 @@ Struct_unpack_impl(PyStructObject *self, Py_buffer *buffer)
assert(self->s_codes != NULL);
if (buffer->len != self->s_size) {
PyErr_Format(StructError,
"unpack requires a bytes object of length %zd",
"unpack requires a buffer of %zd bytes",
self->s_size);
return NULL;
}
Expand Down Expand Up @@ -1734,8 +1735,8 @@ Struct_iter_unpack(PyStructObject *self, PyObject *buffer)
}
if (iter->buf.len % self->s_size != 0) {
PyErr_Format(StructError,
"iterative unpacking requires a bytes length "
"multiple of %zd",
"iterative unpacking requires a buffer of "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"length" is lost.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I delibrately discard it. Now the error messages in struct all get a "requires a buffer of %d bytes" format.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“. . . a buffer of a multiple of . . .” would read better to me. Or simpler: “requires a multiple of . . . bytes”.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"a multiple of %zd bytes",
self->s_size);
Py_DECREF(iter);
return NULL;
Expand Down