Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4171bbe6
Commit
4171bbe6
authored
Apr 15, 2015
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#23949: Improve tuple unpacking error messages.
Patch by Arnon Yaari.
parent
13a6ee0a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
9 deletions
+26
-9
Lib/test/test_unpack.py
Lib/test/test_unpack.py
+1
-1
Lib/test/test_unpack_ex.py
Lib/test/test_unpack_ex.py
+8
-1
Python/ceval.c
Python/ceval.c
+17
-7
No files found.
Lib/test/test_unpack.py
View file @
4171bbe6
...
...
@@ -76,7 +76,7 @@ Unpacking sequence too short
>>> a, b, c, d = Seq()
Traceback (most recent call last):
...
ValueError: n
eed more than 3 values to unpack
ValueError: n
ot enough values to unpack (expected 4, got 3)
Unpacking sequence too long
...
...
Lib/test/test_unpack_ex.py
View file @
4171bbe6
...
...
@@ -85,7 +85,14 @@ Unpacking sequence too short
>>> a, *b, c, d, e = Seq()
Traceback (most recent call last):
...
ValueError: need more than 3 values to unpack
ValueError: not enough values to unpack (expected at least 4, got 3)
Unpacking sequence too short and target appears last
>>> a, b, c, d, *e = Seq()
Traceback (most recent call last):
...
ValueError: not enough values to unpack (expected at least 4, got 3)
Unpacking a sequence where the test for too long raises a different kind of
error
...
...
Python/ceval.c
View file @
4171bbe6
...
...
@@ -3825,9 +3825,17 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
if
(
w
==
NULL
)
{
/* Iterator done, via error or exhaustion. */
if
(
!
PyErr_Occurred
())
{
PyErr_Format
(
PyExc_ValueError
,
"need more than %d value%s to unpack"
,
i
,
i
==
1
?
""
:
"s"
);
if
(
argcntafter
==
-
1
)
{
PyErr_Format
(
PyExc_ValueError
,
"not enough values to unpack (expected %d, got %d)"
,
argcnt
,
i
);
}
else
{
PyErr_Format
(
PyExc_ValueError
,
"not enough values to unpack "
"(expected at least %d, got %d)"
,
argcnt
+
argcntafter
,
i
);
}
}
goto
Error
;
}
...
...
@@ -3844,8 +3852,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
return
1
;
}
Py_DECREF
(
w
);
PyErr_Format
(
PyExc_ValueError
,
"too many values to unpack "
"(expected %d)"
,
argcnt
);
PyErr_Format
(
PyExc_ValueError
,
"too many values to unpack (expected %d)"
,
argcnt
);
goto
Error
;
}
...
...
@@ -3857,8 +3866,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
ll
=
PyList_GET_SIZE
(
l
);
if
(
ll
<
argcntafter
)
{
PyErr_Format
(
PyExc_ValueError
,
"need more than %zd values to unpack"
,
argcnt
+
ll
);
PyErr_Format
(
PyExc_ValueError
,
"not enough values to unpack (expected at least %d, got %zd)"
,
argcnt
+
argcntafter
,
argcnt
+
ll
);
goto
Error
;
}
...
...
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