Commits

Alex Gaynor committed 0fb4abd

Provide a useful exception message.

Comments (0)

Files changed (2)

pypy/module/_io/interp_stringio.py

         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)

pypy/module/_io/test/test_stringio.py

         sio.seek(3)
         r = sio.read()
         assert r == s[3:]
-        raises(TypeError, sio.seek, 0.0)
+        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]