code.put_gotref(item.py_result())
value_node = self.coerced_unpacked_items[i]
value_node.generate_evaluation_code(code)
- code.put_error_if_neg(self.pos,
- "__Pyx_EndUnpack(%s)" % (
- self.iterator.py_result()))
+ code.put_error_if_neg(self.pos, "__Pyx_EndUnpack(%s, %d)" % (
+ self.iterator.py_result(),
+ len(self.args)))
if debug_disposal_code:
print("UnpackNode.generate_assignment_code:")
print("...generating disposal code for %s" % self.iterator)
raise_too_many_values_to_unpack = UtilityCode(
proto = """
-static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void);
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
""",
impl = '''
-static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) {
- PyErr_SetString(PyExc_ValueError, "too many values to unpack");
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
+ PyErr_Format(PyExc_ValueError,
+ #if PY_VERSION_HEX < 0x02050000
+ "too many values to unpack (expected %d)", (int)expected);
+ #else
+ "too many values to unpack (expected %zd)", expected);
+ #endif
}
''')
} else if (PyTuple_GET_SIZE(t) < index) {
__Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
} else {
- __Pyx_RaiseTooManyValuesError();
+ __Pyx_RaiseTooManyValuesError(index);
}
}
""",
unpacking_utility_code = UtilityCode(
proto = """
static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
-static int __Pyx_EndUnpack(PyObject *); /*proto*/
+static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/
""",
impl = """
static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
return item;
}
-static int __Pyx_EndUnpack(PyObject *iter) {
+static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) {
PyObject *item;
if ((item = PyIter_Next(iter))) {
Py_DECREF(item);
- __Pyx_RaiseTooManyValuesError();
+ __Pyx_RaiseTooManyValuesError(expected);
return -1;
}
else if (!PyErr_Occurred())
ValueError: need more than 2 values to unpack
>>> assign3((1,2,3,4))
Traceback (most recent call last):
- ValueError: too many values to unpack
+ ValueError: too many values to unpack (expected 3)
"""
a,b,c = t
return (a,b,c)
>>> assign3_typed((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
- >>> a,b,c = (1,2,3,4)
+ >>> a,b,c = (1,2,3,4) # doctest: +ELLIPSIS
Traceback (most recent call last):
- ValueError: too many values to unpack
+ ValueError: too many values to unpack...
>>> assign3_typed((1,2,3,4))
Traceback (most recent call last):
- ValueError: too many values to unpack
+ ValueError: too many values to unpack (expected 3)
>>> a,b = 99,98
- >>> a,b = t
+ >>> a,b = t # doctest: +ELLIPSIS
Traceback (most recent call last):
- ValueError: too many values to unpack
+ ValueError: too many values to unpack...
>>> a,b
(99, 98)
"""