Author: Armin Rigo <[email protected]>
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'")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to