Commits

Alex Gaynor committed e4ce179

Fix for str(IOError(1, 2))

  • Participants
  • Parent commits 76f4a40

Comments (0)

Files changed (2)

File pypy/module/exceptions/interp_exceptions.py

     def descr_str(self, space):
         if (not space.is_w(self.w_errno, space.w_None) and
             not space.is_w(self.w_strerror, space.w_None)):
+            errno = space.str_w(space.str(self.w_errno))
+            strerror = space.str_w(space.str(self.w_strerror))
             if not space.is_w(self.w_filename, space.w_None):
                 return space.wrap("[Errno %s] %s: %s" % (
-                    space.str_w(space.str(self.w_errno)),
-                    space.str_w(self.w_strerror),
+                    errno,
+                    strerror,
                     space.str_w(space.repr(self.w_filename))))
-            return space.wrap("[Errno %s] %s" %
-                              (space.str_w(space.str(self.w_errno)),
-                               space.str_w(self.w_strerror)))
+            return space.wrap("[Errno %s] %s" % (
+                errno,
+                strerror,
+            ))
         return W_BaseException.descr_str(self, space)
 
 W_EnvironmentError.typedef = TypeDef(

File pypy/module/exceptions/test/test_exc.py

         assert repr(Exception(3, "x")) == "Exception(3, 'x')"
         assert str(IOError("foo", "bar")) == "[Errno foo] bar"
         assert isinstance(IOError("foo", "bar"), IOError)
+        assert str(IOError(1, 2)) == "[Errno 1] 2"
 
     def test_custom_class(self):
         from exceptions import Exception, BaseException, LookupError