diff options
author | Petri Lehtinen <petri@digip.org> | 2012-10-29 19:25:01 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2012-10-29 19:25:01 (GMT) |
commit | 4648b4779acd3d75d5f4b0b1438cb2af51cc06b2 (patch) | |
tree | d2ec74c5846f9a462fdb278b1d6424d8b9dafb01 /Modules | |
parent | 646eb1e8566821bd0129ce1ef5d300168856010e (diff) | |
parent | 92c28cace45261ae06c5361aef661a01f58a5413 (diff) | |
download | cpython-4648b4779acd3d75d5f4b0b1438cb2af51cc06b2.zip cpython-4648b4779acd3d75d5f4b0b1438cb2af51cc06b2.tar.gz cpython-4648b4779acd3d75d5f4b0b1438cb2af51cc06b2.tar.bz2 |
#14897: Enhance error messages of struct.pack and struct.pack_into
Patch by Matti Mäki.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_struct.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c index 0b20e26..0cd0512 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1662,7 +1662,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; } @@ -1701,9 +1701,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; } |