[pypy-commit] pypy py3.5: fix error message
arigo
pypy.commits at gmail.com
Thu Nov 10 03:59:17 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88288:3fff80d67303
Date: 2016-11-10 09:58 +0100
http://bitbucket.org/pypy/pypy/changeset/3fff80d67303/
Log: fix error message
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -716,9 +716,15 @@
if mytype.method != '' and e.match(space, space.w_TypeError):
try:
item = unwrap(space.call_method(w_item, mytype.method))
- except OperationError:
- raise oefmt(space.w_TypeError,
- "array item must be " + mytype.unwrap[:-2])
+ except OperationError as e:
+ if e.async(space):
+ raise
+ if space.isinstance_w(w_item, space.w_unicode):
+ msg = ("cannot use a str to initialize an array"
+ " with typecode '" + mytype.typecode + "'")
+ else:
+ msg = "array item must be " + mytype.unwrap[:-2]
+ raise OperationError(space.w_TypeError, space.wrap(msg))
else:
raise
if mytype.convert:
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -1158,3 +1158,9 @@
it = iter(array.array('b'))
assert list(it) == []
assert list(iter(it)) == []
+
+ def test_array_cannot_use_str(self):
+ import array
+ e = raises(TypeError, array.array, 'i', 'abcd')
+ assert str(e.value) == ("cannot use a str to initialize an array"
+ " with typecode 'i'")
More information about the pypy-commit
mailing list