[pypy-commit] pypy py3.5: Change error message on unpack and extended unpack if there are more values expected than available
raffael_t
pypy.commits at gmail.com
Tue Aug 23 07:36:48 EDT 2016
Author: Raffael Tfirst <raffael.tfirst at gmail.com>
Branch: py3.5
Changeset: r86443:0a1d00e6444f
Date: 2016-08-23 13:36 +0200
http://bitbucket.org/pypy/pypy/changeset/0a1d00e6444f/
Log: Change error message on unpack and extended unpack if there are more
values expected than available
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -942,8 +942,8 @@
idx += 1
if idx < expected_length:
raise oefmt(self.w_ValueError,
- "need more than %d value%s to unpack",
- idx, "" if idx == 1 else "s")
+ "not enough values to unpack (expected %d, got %d)",
+ expected_length, idx)
return items
def unpackiterable_unroll(self, w_iterable, expected_length):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -820,13 +820,9 @@
itemcount = len(items)
count = left + right
if count > itemcount:
- if count == 1:
- plural = ''
- else:
- plural = 's'
raise oefmt(self.space.w_ValueError,
- "need more than %d value%s to unpack",
- itemcount, plural)
+ "not enough values to unpack (expected at least %d, got %d)",
+ count, itemcount)
right = itemcount - right
assert right >= 0
# push values in reverse order
diff --git a/pypy/interpreter/test/test_interpreter.py b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -458,7 +458,7 @@
try:
a, *b, c, d, e = Seq()
except ValueError as e:
- assert str(e) == "need more than 3 values to unpack"
+ assert str(e) == "not enough values to unpack (expected at least 4, got 3)"
else:
assert False, "Expected ValueError"
"""
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -401,8 +401,8 @@
"too many values to unpack (expected %d)", expected)
else:
raise oefmt(self.w_ValueError,
- "need more than %d value%s to unpack",
- got, "" if got == 1 else "s")
+ "not enough values to unpack (expected %d, got %d)",
+ expected, got)
def unpackiterable(self, w_obj, expected_length=-1):
if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
More information about the pypy-commit
mailing list