Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
8f8ef5cd
Commit
8f8ef5cd
authored
Jul 17, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better error message for tuple unpacking, following Python 3.2 (including a test fix)
parent
9f5cace1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
16 deletions
+21
-16
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+15
-10
tests/run/tupleassign.pyx
tests/run/tupleassign.pyx
+6
-6
No files found.
Cython/Compiler/ExprNodes.py
View file @
8f8ef5cd
...
@@ -3642,9 +3642,9 @@ class SequenceNode(ExprNode):
...
@@ -3642,9 +3642,9 @@ class SequenceNode(ExprNode):
code
.
put_gotref
(
item
.
py_result
())
code
.
put_gotref
(
item
.
py_result
())
value_node
=
self
.
coerced_unpacked_items
[
i
]
value_node
=
self
.
coerced_unpacked_items
[
i
]
value_node
.
generate_evaluation_code
(
code
)
value_node
.
generate_evaluation_code
(
code
)
code
.
put_error_if_neg
(
self
.
pos
,
code
.
put_error_if_neg
(
self
.
pos
,
"__Pyx_EndUnpack(%s, %d)"
%
(
"__Pyx_EndUnpack(%s)"
%
(
self
.
iterator
.
py_result
(),
self
.
iterator
.
py_result
(
)))
len
(
self
.
args
)))
if
debug_disposal_code
:
if
debug_disposal_code
:
print
(
"UnpackNode.generate_assignment_code:"
)
print
(
"UnpackNode.generate_assignment_code:"
)
print
(
"...generating disposal code for %s"
%
self
.
iterator
)
print
(
"...generating disposal code for %s"
%
self
.
iterator
)
...
@@ -6981,11 +6981,16 @@ impl = """
...
@@ -6981,11 +6981,16 @@ impl = """
raise_too_many_values_to_unpack
=
UtilityCode
(
raise_too_many_values_to_unpack
=
UtilityCode
(
proto
=
"""
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(
voi
d);
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(
Py_ssize_t expecte
d);
"""
,
"""
,
impl
=
'''
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) {
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
PyErr_SetString(PyExc_ValueError, "too many values to unpack");
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
}
}
'''
)
'''
)
...
@@ -7018,7 +7023,7 @@ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
...
@@ -7018,7 +7023,7 @@ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
} else if (PyTuple_GET_SIZE(t) < index) {
} else if (PyTuple_GET_SIZE(t) < index) {
__Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
__Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
} else {
} else {
__Pyx_RaiseTooManyValuesError();
__Pyx_RaiseTooManyValuesError(
index
);
}
}
}
}
"""
,
"""
,
...
@@ -7030,7 +7035,7 @@ requires = [raise_none_iter_error_utility_code,
...
@@ -7030,7 +7035,7 @@ requires = [raise_none_iter_error_utility_code,
unpacking_utility_code
=
UtilityCode
(
unpacking_utility_code
=
UtilityCode
(
proto
=
"""
proto
=
"""
static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*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
=
"""
impl
=
"""
static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
...
@@ -7043,11 +7048,11 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
...
@@ -7043,11 +7048,11 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
return item;
return item;
}
}
static int __Pyx_EndUnpack(PyObject *iter) {
static int __Pyx_EndUnpack(PyObject *iter
, Py_ssize_t expected
) {
PyObject *item;
PyObject *item;
if ((item = PyIter_Next(iter))) {
if ((item = PyIter_Next(iter))) {
Py_DECREF(item);
Py_DECREF(item);
__Pyx_RaiseTooManyValuesError();
__Pyx_RaiseTooManyValuesError(
expected
);
return -1;
return -1;
}
}
else if (!PyErr_Occurred())
else if (!PyErr_Occurred())
...
...
tests/run/tupleassign.pyx
View file @
8f8ef5cd
...
@@ -15,7 +15,7 @@ def assign3(t):
...
@@ -15,7 +15,7 @@ def assign3(t):
ValueError: need more than 2 values to unpack
ValueError: need more than 2 values to unpack
>>> assign3((1,2,3,4))
>>> assign3((1,2,3,4))
Traceback (most recent call last):
Traceback (most recent call last):
ValueError: too many values to unpack
ValueError: too many values to unpack
(expected 3)
"""
"""
a
,
b
,
c
=
t
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
return
(
a
,
b
,
c
)
...
@@ -39,16 +39,16 @@ def assign3_typed(tuple t):
...
@@ -39,16 +39,16 @@ def assign3_typed(tuple t):
>>> assign3_typed((1,2))
>>> assign3_typed((1,2))
Traceback (most recent call last):
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
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):
Traceback (most recent call last):
ValueError: too many values to unpack
ValueError: too many values to unpack
...
>>> assign3_typed((1,2,3,4))
>>> assign3_typed((1,2,3,4))
Traceback (most recent call last):
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 = 99,98
>>> a,b = t
>>> a,b = t
# doctest: +ELLIPSIS
Traceback (most recent call last):
Traceback (most recent call last):
ValueError: too many values to unpack
ValueError: too many values to unpack
...
>>> a,b
>>> a,b
(99, 98)
(99, 98)
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment