summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-10-29 19:26:56 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-10-29 19:26:56 (GMT)
commitf1380557e3c647218bcb1bd1d4465cd9563a25bc (patch)
treee05e9bf4b94ca678dd2584fb07b061a041a7b608 /Modules
parent2bb842a2ef771b73cf3e0308c4341b0ecc56d9fd (diff)
parent4648b4779acd3d75d5f4b0b1438cb2af51cc06b2 (diff)
downloadcpython-f1380557e3c647218bcb1bd1d4465cd9563a25bc.zip
cpython-f1380557e3c647218bcb1bd1d4465cd9563a25bc.tar.gz
cpython-f1380557e3c647218bcb1bd1d4465cd9563a25bc.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.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 0f50144..6e8759b 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -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;
}