mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#14897: Enhance error messages of struct.pack and struct.pack_into
Patch by Matti Mäki.
This commit is contained in:
commit
f1380557e3
3 changed files with 18 additions and 4 deletions
|
@ -1661,7 +1661,7 @@ s_pack(PyObject *self, PyObject *args)
|
|||
if (PyTuple_GET_SIZE(args) != soself->s_len)
|
||||
{
|
||||
PyErr_Format(StructError,
|
||||
"pack requires exactly %zd arguments", soself->s_len);
|
||||
"pack expected %zd items for packing (got %zd)", soself->s_len, PyTuple_GET_SIZE(args));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1700,9 +1700,19 @@ s_pack_into(PyObject *self, PyObject *args)
|
|||
assert(soself->s_codes != NULL);
|
||||
if (PyTuple_GET_SIZE(args) != (soself->s_len + 2))
|
||||
{
|
||||
PyErr_Format(StructError,
|
||||
"pack_into requires exactly %zd arguments",
|
||||
(soself->s_len + 2));
|
||||
if (PyTuple_GET_SIZE(args) == 0) {
|
||||
PyErr_Format(StructError,
|
||||
"pack_into expected buffer argument");
|
||||
}
|
||||
else if (PyTuple_GET_SIZE(args) == 1) {
|
||||
PyErr_Format(StructError,
|
||||
"pack_into expected offset argument");
|
||||
}
|
||||
else {
|
||||
PyErr_Format(StructError,
|
||||
"pack_into expected %zd items for packing (got %zd)",
|
||||
soself->s_len, (PyTuple_GET_SIZE(args) - 2));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue