[pypy-svn] pypy default: Provide a useful exception message.

alex_gaynor commits-noreply at bitbucket.org
Fri Jan 28 23:27:13 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41437:0fb4abd312bd
Date: 2011-01-28 17:26 -0500
http://bitbucket.org/pypy/pypy/changeset/0fb4abd312bd/

Log:	Provide a useful exception message.

diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -47,4 +47,14 @@
         sio.seek(3)
         r = sio.read()
         assert r == s[3:]
-        raises(TypeError, sio.seek, 0.0)
\ No newline at end of file
+        raises(TypeError, sio.seek, 0.0)
+
+    def test_write_error(self):
+        import io
+
+        exc_info = raises(TypeError, io.StringIO, 3)
+        assert "int" in exc_info.value.args[0]
+
+        sio = io.StringIO(u"")
+        exc_info = raises(TypeError, sio.write, 3)
+        assert "int" in exc_info.value.args[0]
\ No newline at end of file

diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -52,7 +52,7 @@
         if not space.isinstance_w(w_obj, space.w_unicode):
             raise operationerrfmt(space.w_TypeError,
                                   "string argument expected, got '%s'",
-                                  space.type(self).getname(space, '?'))
+                                  space.type(w_obj).getname(space, '?'))
         self._check_closed(space)
         string = space.unicode_w(w_obj)
         size = len(string)


More information about the Pypy-commit mailing list