[pypy-commit] pypy py3.6: refactor wrap_oserror: remove exception_name

mattip pypy.commits at gmail.com
Mon Feb 3 15:11:33 EST 2020


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r98653:f2a9f4b83a5a
Date: 2020-02-03 22:04 +0200
http://bitbucket.org/pypy/pypy/changeset/f2a9f4b83a5a/

Log:	refactor wrap_oserror: remove exception_name

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -606,8 +606,8 @@
     ansi_print(text, esc="31", file=file, newline=newline)
 
 @specialize.arg(3, 6)
-def wrap_oserror2(space, e, w_filename=None, exception_name='w_OSError',
-                  w_exception_class=None, w_filename2=None, eintr_retry=False):
+def wrap_oserror2(space, e, w_filename=None, w_exception_class=None,
+                  w_filename2=None, eintr_retry=False):
     """A double API here:
 
         * if eintr_retry is False, always return the OperationError to
@@ -623,7 +623,7 @@
     assert isinstance(e, OSError)
 
     if w_exception_class is None:
-        w_exc = getattr(space, exception_name)
+        w_exc = space.w_OSError
     else:
         w_exc = w_exception_class
     operror = _wrap_oserror2_impl(space, e, w_filename, w_filename2, w_exc,
@@ -679,8 +679,8 @@
 
 @specialize.arg(3, 6)
 @dont_inline
-def wrap_oserror(space, e, filename=None, exception_name='w_OSError',
-                 w_exception_class=None, filename2=None, eintr_retry=False):
+def wrap_oserror(space, e, filename=None, w_exception_class=None,
+                 filename2=None, eintr_retry=False):
     w_filename = None
     w_filename2 = None
     if filename is not None:
@@ -688,7 +688,6 @@
         if filename2 is not None:
             w_filename2 = space.newfilename(filename2)
     return wrap_oserror2(space, e, w_filename,
-                         exception_name=exception_name,
                          w_exception_class=w_exception_class,
                          w_filename2=w_filename2,
                          eintr_retry=eintr_retry)
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -195,7 +195,7 @@
                             break
                         except OSError as e:
                             wrap_oserror2(space, e, w_name,
-                                          exception_name='w_IOError',
+                                          w_exception_class=space.w_IOError,
                                           eintr_retry=True)
                     try:
                          _open_inhcache.set_non_inheritable(self.fd)
@@ -235,7 +235,7 @@
             # directories, so we need a check.
             if stat.S_ISDIR(st.st_mode):
                 raise wrap_oserror2(space, OSError(errno.EISDIR, "fstat"),
-                                    w_name, exception_name='w_IOError',
+                                    w_name, w_exception_class=space.w_IOError,
                                     eintr_retry=False)
             self.blksize = DEFAULT_BUFFER_SIZE
             if HAS_BLKSIZE and st.st_blksize > 1:
@@ -251,7 +251,7 @@
                 try:
                     os.lseek(self.fd, 0, os.SEEK_END)
                 except OSError as e:
-                    raise wrap_oserror(space, e, exception_name='w_IOError',
+                    raise wrap_oserror(space, e, w_exception_class=space.w_IOError,
                                        eintr_retry=False)
         except:
             if not fd_is_own:
@@ -311,7 +311,7 @@
             os.close(fd)
         except OSError as e:
             raise wrap_oserror(space, e,
-                               exception_name='w_IOError',
+                               w_exception_class=space.w_IOError,
                                eintr_retry=False)
 
     def close_w(self, space):
@@ -346,7 +346,7 @@
             pos = os.lseek(self.fd, pos, whence)
         except OSError as e:
             raise wrap_oserror(space, e,
-                               exception_name='w_IOError',
+                               w_exception_class=space.w_IOError,
                                eintr_retry=False)
         return space.newint(pos)
 
@@ -356,7 +356,7 @@
             pos = os.lseek(self.fd, 0, 1)
         except OSError as e:
             raise wrap_oserror(space, e,
-                               exception_name='w_IOError',
+                               w_exception_class=space.w_IOError,
                                eintr_retry=False)
         return space.newint(pos)
 
@@ -390,7 +390,7 @@
         try:
             res = os.isatty(self.fd)
         except OSError as e:
-            raise wrap_oserror(space, e, exception_name='w_IOError',
+            raise wrap_oserror(space, e, w_exception_class=space.w_IOError,
                                eintr_retry=False)
         return space.newbool(res)
 
@@ -425,7 +425,7 @@
                 if e.errno == errno.EAGAIN:
                     return space.w_None
                 wrap_oserror(space, e,
-                             exception_name='w_IOError',
+                             w_exception_class=space.w_IOError,
                              eintr_retry=True)
 
         return space.newint(n)
@@ -446,7 +446,7 @@
                 if e.errno == errno.EAGAIN:
                     return space.w_None
                 wrap_oserror(space, e,
-                             exception_name='w_IOError',
+                             w_exception_class=space.w_IOError,
                              eintr_retry=True)
 
         return space.newbytes(s)
@@ -473,7 +473,7 @@
                 except OSError as e:
                     if e.errno == errno.EAGAIN:
                         return space.w_None
-                    wrap_oserror(space, e, exception_name='w_IOError',
+                    wrap_oserror(space, e, w_exception_class=space.w_IOError,
                                  eintr_retry=True)
             self.output_slice(space, rwbuffer, 0, buf)
             return space.newint(len(buf))
@@ -491,7 +491,7 @@
                     if err == errno.EAGAIN:
                         return space.w_None
                     e = OSError(err, "read failed")
-                    wrap_oserror(space, e, exception_name='w_IOError',
+                    wrap_oserror(space, e, w_exception_class=space.w_IOError,
                                  eintr_retry=True)
 
     def readall_w(self, space):
@@ -510,7 +510,7 @@
                     if total > 0:
                         break   # return what we've got so far
                     return space.w_None
-                wrap_oserror(space, e, exception_name='w_IOError',
+                wrap_oserror(space, e, w_exception_class=space.w_IOError,
                              eintr_retry=True)
                 continue
             if not chunk:
@@ -536,7 +536,7 @@
         try:
             self._truncate(space.r_longlong_w(w_size))
         except OSError as e:
-            raise wrap_oserror(space, e, exception_name='w_IOError',
+            raise wrap_oserror(space, e, w_exception_class=space.w_IOError,
                                eintr_retry=False)
 
         return w_size
diff --git a/pypy/module/fcntl/interp_fcntl.py b/pypy/module/fcntl/interp_fcntl.py
--- a/pypy/module/fcntl/interp_fcntl.py
+++ b/pypy/module/fcntl/interp_fcntl.py
@@ -82,13 +82,13 @@
     # when appropriate
     errno = rposix.get_saved_errno()
     wrap_oserror(space, OSError(errno, funcname),
-                 exception_name = 'w_IOError', eintr_retry=True)
+                 w_exception_class=space.w_IOError, eintr_retry=True)
 
 def _raise_error_always(space, funcname):
     # this variant never returns normally, and doesn't retry if it gets EINTR.
     errno = rposix.get_saved_errno()
     raise wrap_oserror(space, OSError(errno, funcname),
-                       exception_name = 'w_IOError', eintr_retry=False)
+                       w_exception_class=space.w_IOError, eintr_retry=False)
 
 @unwrap_spec(op=int, w_arg=WrappedDefault(0))
 def fcntl(space, w_fd, op, w_arg):


More information about the pypy-commit mailing list