Issue #16706: get rid of os.error
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index fa77ec1..7aa43e0 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -200,7 +200,7 @@
         buffering = DEFAULT_BUFFER_SIZE
         try:
             bs = os.fstat(raw.fileno()).st_blksize
-        except (os.error, AttributeError):
+        except (OSError, AttributeError):
             pass
         else:
             if bs > 1:
diff --git a/Lib/cgi.py b/Lib/cgi.py
index e964f0c..4222ef2 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -949,7 +949,7 @@
     print("<H3>Current Working Directory:</H3>")
     try:
         pwd = os.getcwd()
-    except os.error as msg:
+    except OSError as msg:
         print("os.error:", html.escape(str(msg)))
     else:
         print(html.escape(pwd))
diff --git a/Lib/compileall.py b/Lib/compileall.py
index fd22fc3c..a47e84f 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -38,7 +38,7 @@
         print('Listing {!r}...'.format(dir))
     try:
         names = os.listdir(dir)
-    except os.error:
+    except OSError:
         print("Can't list {!r}".format(dir))
         names = []
     names.sort()
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index cfb9123..0bb3a89 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -100,12 +100,12 @@
 
         try:
             self._os.unlink(self._bakfile)
-        except self._os.error:
+        except OSError:
             pass
 
         try:
             self._os.rename(self._dirfile, self._bakfile)
-        except self._os.error:
+        except OSError:
             pass
 
         f = self._io.open(self._dirfile, 'w', encoding="Latin-1")
diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index 260332a..a43d725 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -148,7 +148,7 @@
             dist.run_commands()
         except KeyboardInterrupt:
             raise SystemExit("interrupted")
-        except (IOError, os.error) as exc:
+        except (IOError, OSError) as exc:
             error = grok_environment_error(exc)
 
             if DEBUG:
diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py
index 2826ff8..7d1c78a 100644
--- a/Lib/distutils/dir_util.py
+++ b/Lib/distutils/dir_util.py
@@ -124,7 +124,7 @@
               "cannot copy tree '%s': not a directory" % src)
     try:
         names = os.listdir(src)
-    except os.error as e:
+    except OSError as e:
         (errno, errstr) = e
         if dry_run:
             names = []
diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py
index 9bdd14e..f6ed290 100644
--- a/Lib/distutils/file_util.py
+++ b/Lib/distutils/file_util.py
@@ -27,26 +27,26 @@
     try:
         try:
             fsrc = open(src, 'rb')
-        except os.error as e:
+        except OSError as e:
             raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
 
         if os.path.exists(dst):
             try:
                 os.unlink(dst)
-            except os.error as e:
+            except OSError as e:
                 raise DistutilsFileError(
                       "could not delete '%s': %s" % (dst, e.strerror))
 
         try:
             fdst = open(dst, 'wb')
-        except os.error as e:
+        except OSError as e:
             raise DistutilsFileError(
                   "could not create '%s': %s" % (dst, e.strerror))
 
         while True:
             try:
                 buf = fsrc.read(buffer_size)
-            except os.error as e:
+            except OSError as e:
                 raise DistutilsFileError(
                       "could not read from '%s': %s" % (src, e.strerror))
 
@@ -55,7 +55,7 @@
 
             try:
                 fdst.write(buf)
-            except os.error as e:
+            except OSError as e:
                 raise DistutilsFileError(
                       "could not write to '%s': %s" % (dst, e.strerror))
     finally:
@@ -193,7 +193,7 @@
     copy_it = False
     try:
         os.rename(src, dst)
-    except os.error as e:
+    except OSError as e:
         (num, msg) = e
         if num == errno.EXDEV:
             copy_it = True
@@ -205,11 +205,11 @@
         copy_file(src, dst, verbose=verbose)
         try:
             os.unlink(src)
-        except os.error as e:
+        except OSError as e:
             (num, msg) = e
             try:
                 os.unlink(dst)
-            except os.error:
+            except OSError:
                 pass
             raise DistutilsFileError(
                   "couldn't move '%s' to '%s' by copy/delete: "
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index dbbbb21..5be0318 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -324,8 +324,10 @@
                 if self._inplace:
                     self._backupfilename = (
                         self._filename + (self._backup or ".bak"))
-                    try: os.unlink(self._backupfilename)
-                    except os.error: pass
+                    try:
+                        os.unlink(self._backupfilename)
+                    except OSError:
+                        pass
                     # The next few lines may raise IOError
                     os.rename(self._filename, self._backupfilename)
                     self._file = open(self._backupfilename, self._mode)
diff --git a/Lib/genericpath.py b/Lib/genericpath.py
index 2174187..943fdb3 100644
--- a/Lib/genericpath.py
+++ b/Lib/genericpath.py
@@ -16,7 +16,7 @@
     """Test whether a path exists.  Returns False for broken symbolic links"""
     try:
         os.stat(path)
-    except os.error:
+    except OSError:
         return False
     return True
 
@@ -27,7 +27,7 @@
     """Test whether a path is a regular file"""
     try:
         st = os.stat(path)
-    except os.error:
+    except OSError:
         return False
     return stat.S_ISREG(st.st_mode)
 
@@ -39,7 +39,7 @@
     """Return true if the pathname refers to an existing directory."""
     try:
         st = os.stat(s)
-    except os.error:
+    except OSError:
         return False
     return stat.S_ISDIR(st.st_mode)
 
diff --git a/Lib/glob.py b/Lib/glob.py
index 3c9c30c..33ee43b 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -55,7 +55,7 @@
             dirname = os.curdir
     try:
         names = os.listdir(dirname)
-    except os.error:
+    except OSError:
         return []
     if pattern[0] != '.':
         names = [x for x in names if x[0] != '.']
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 7167142..e549982 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -732,7 +732,7 @@
         """
         try:
             list = os.listdir(path)
-        except os.error:
+        except OSError:
             self.send_error(404, "No permission to list directory")
             return None
         list.sort(key=lambda a: a.lower())
@@ -1123,7 +1123,7 @@
             try:
                 try:
                     os.setuid(nobody)
-                except os.error:
+                except OSError:
                     pass
                 os.dup2(self.rfile.fileno(), 0)
                 os.dup2(self.wfile.fileno(), 1)
diff --git a/Lib/lib2to3/main.py b/Lib/lib2to3/main.py
index f9cc18b..93bae90 100644
--- a/Lib/lib2to3/main.py
+++ b/Lib/lib2to3/main.py
@@ -90,11 +90,11 @@
             if os.path.lexists(backup):
                 try:
                     os.remove(backup)
-                except os.error as err:
+                except OSError as err:
                     self.log_message("Can't remove backup %s", backup)
             try:
                 os.rename(filename, backup)
-            except os.error as err:
+            except OSError as err:
                 self.log_message("Can't rename %s to %s", filename, backup)
         # Actually write the new file
         write = super(StdoutRefactoringTool, self).write_file
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 201e193..87f686e 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -534,12 +534,12 @@
         """
         try:
             f = _open_with_encoding(filename, "w", encoding=encoding)
-        except os.error as err:
+        except OSError as err:
             self.log_error("Can't create %s: %s", filename, err)
             return
         try:
             f.write(_to_system_newlines(new_text))
-        except os.error as err:
+        except OSError as err:
             self.log_error("Can't write %s: %s", filename, err)
         finally:
             f.close()
diff --git a/Lib/lib2to3/tests/pytree_idempotency.py b/Lib/lib2to3/tests/pytree_idempotency.py
index a02bbfe..731c403 100755
--- a/Lib/lib2to3/tests/pytree_idempotency.py
+++ b/Lib/lib2to3/tests/pytree_idempotency.py
@@ -53,7 +53,7 @@
     for dir in sys.path:
         try:
             names = os.listdir(dir)
-        except os.error:
+        except OSError:
             continue
         print("Scanning", dir, "...", file=sys.stderr)
         for name in names:
diff --git a/Lib/linecache.py b/Lib/linecache.py
index c3f2c3f..71dc93d 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -59,7 +59,7 @@
             continue   # no-op for files loaded via a __loader__
         try:
             stat = os.stat(fullname)
-        except os.error:
+        except OSError:
             del cache[filename]
             continue
         if size != stat.st_size or mtime != stat.st_mtime:
@@ -118,7 +118,7 @@
             try:
                 stat = os.stat(fullname)
                 break
-            except os.error:
+            except OSError:
                 pass
         else:
             return []
diff --git a/Lib/macpath.py b/Lib/macpath.py
index 1615d91..d34f9e94 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -127,7 +127,7 @@
 
     try:
         st = os.lstat(path)
-    except os.error:
+    except OSError:
         return False
     return True
 
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index 683e305..7418a9ce6 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -228,7 +228,7 @@
         for dir in m.__path__:
             try:
                 names = os.listdir(dir)
-            except os.error:
+            except OSError:
                 self.msg(2, "can't list directory", dir)
                 continue
             for name in names:
diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py
index a0b3d68..d3e7a10 100644
--- a/Lib/multiprocessing/forking.py
+++ b/Lib/multiprocessing/forking.py
@@ -111,7 +111,7 @@
             if self.returncode is None:
                 try:
                     pid, sts = os.waitpid(self.pid, flag)
-                except os.error:
+                except OSError:
                     # Child process not yet created. See #1731717
                     # e.errno == errno.ECHILD == 10
                     return None
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f70193f..12494c5 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -321,7 +321,7 @@
     """
     try:
         st = os.lstat(path)
-    except (os.error, AttributeError):
+    except (OSError, AttributeError):
         return False
     return stat.S_ISLNK(st.st_mode)
 
@@ -331,7 +331,7 @@
     """Test whether a path exists.  Returns True for broken symbolic links"""
     try:
         st = os.lstat(path)
-    except (os.error, WindowsError):
+    except (OSError, WindowsError):
         return False
     return True
 
diff --git a/Lib/os.py b/Lib/os.py
index 8241f36..5f11fdf 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -338,7 +338,7 @@
 
     By default errors from the os.listdir() call are ignored.  If
     optional arg 'onerror' is specified, it should be a function; it
-    will be called with one argument, an os.error instance.  It can
+    will be called with one argument, an OSError instance.  It can
     report the error to continue with the walk, or raise the exception
     to abort the walk.  Note that the filename is available as the
     filename attribute of the exception object.
diff --git a/Lib/platform.py b/Lib/platform.py
index db08eab..5629691 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -316,7 +316,7 @@
     """
     try:
         etc = os.listdir('/etc')
-    except os.error:
+    except OSError:
         # Probably not a Unix system
         return distname,version,id
     etc.sort()
@@ -424,10 +424,10 @@
             pipe = popen(cmd)
             info = pipe.read()
             if pipe.close():
-                raise os.error('command failed')
+                raise OSError('command failed')
             # XXX How can I suppress shell errors from being written
             #     to stderr ?
-        except os.error as why:
+        except OSError as why:
             #print 'Command %s failed: %s' % (cmd,why)
             continue
         except IOError as why:
@@ -906,7 +906,7 @@
         return default
     try:
         f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
-    except (AttributeError,os.error):
+    except (AttributeError, OSError):
         return default
     output = f.read().strip()
     rc = f.close()
@@ -932,7 +932,7 @@
         proc = subprocess.Popen(['file', target],
                 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 
-    except (AttributeError,os.error):
+    except (AttributeError, OSError):
         return default
     output = proc.communicate()[0].decode('latin-1')
     rc = proc.wait()
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index cb93796..eb5f45f 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -162,7 +162,7 @@
     """Test whether a path is a symbolic link"""
     try:
         st = os.lstat(path)
-    except (os.error, AttributeError):
+    except (OSError, AttributeError):
         return False
     return stat.S_ISLNK(st.st_mode)
 
@@ -172,7 +172,7 @@
     """Test whether a path exists.  Returns True for broken symbolic links"""
     try:
         os.lstat(path)
-    except os.error:
+    except OSError:
         return False
     return True
 
@@ -220,7 +220,7 @@
         else:
             parent = join(path, '..')
         s2 = os.lstat(parent)
-    except os.error:
+    except OSError:
         return False # It doesn't exist -- so not a mount point :-)
     dev1 = s1.st_dev
     dev2 = s2.st_dev
diff --git a/Lib/pty.py b/Lib/pty.py
index 3b79202..786ce04 100644
--- a/Lib/pty.py
+++ b/Lib/pty.py
@@ -57,17 +57,17 @@
         try:
             tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
         except IOError as msg:
-            raise os.error(msg)
+            raise OSError(msg)
         return master_fd, tty_name
     for x in 'pqrstuvwxyzPQRST':
         for y in '0123456789abcdef':
             pty_name = '/dev/pty' + x + y
             try:
                 fd = os.open(pty_name, os.O_RDWR)
-            except os.error:
+            except OSError:
                 continue
             return (fd, '/dev/tty' + x + y)
-    raise os.error('out of pty devices')
+    raise OSError('out of pty devices')
 
 def slave_open(tty_name):
     """slave_open(tty_name) -> slave_fd
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 1eb4733..9a79f85 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -356,24 +356,24 @@
     names = []
     try:
         names = os.listdir(path)
-    except os.error:
+    except OSError:
         onerror(os.listdir, path, sys.exc_info())
     for name in names:
         fullname = os.path.join(path, name)
         try:
             mode = os.lstat(fullname).st_mode
-        except os.error:
+        except OSError:
             mode = 0
         if stat.S_ISDIR(mode):
             _rmtree_unsafe(fullname, onerror)
         else:
             try:
                 os.unlink(fullname)
-            except os.error:
+            except OSError:
                 onerror(os.unlink, fullname, sys.exc_info())
     try:
         os.rmdir(path)
-    except os.error:
+    except OSError:
         onerror(os.rmdir, path, sys.exc_info())
 
 # Version using fd-based APIs to protect against races
@@ -464,7 +464,7 @@
                 _rmtree_safe_fd(fd, path, onerror)
                 try:
                     os.rmdir(path)
-                except os.error:
+                except OSError:
                     onerror(os.rmdir, path, sys.exc_info())
             else:
                 try:
diff --git a/Lib/site.py b/Lib/site.py
index 5d63c75..982dbc8 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -196,7 +196,7 @@
         known_paths.add(sitedircase)
     try:
         names = os.listdir(sitedir)
-    except os.error:
+    except OSError:
         return
     names = [name for name in names if name.endswith(".pth")]
     for name in sorted(names):
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index a21318d..902a534 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -532,7 +532,7 @@
             # children.
             try:
                 pid, status = os.waitpid(0, 0)
-            except os.error:
+            except OSError:
                 pid = None
             if pid not in self.active_children: continue
             self.active_children.remove(pid)
@@ -545,7 +545,7 @@
         for child in self.active_children:
             try:
                 pid, status = os.waitpid(child, os.WNOHANG)
-            except os.error:
+            except OSError:
                 pid = None
             if not pid: continue
             try:
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 50d7cfd..b042d26 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1444,7 +1444,7 @@
 
 
         def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
-                _WNOHANG=os.WNOHANG, _os_error=os.error):
+                _WNOHANG=os.WNOHANG):
             """Check if child process has terminated.  Returns returncode
             attribute.
 
@@ -1457,7 +1457,7 @@
                     pid, sts = _waitpid(self.pid, _WNOHANG)
                     if pid == self.pid:
                         self._handle_exitstatus(sts)
-                except _os_error as e:
+                except OSError as e:
                     if _deadstate is not None:
                         self.returncode = _deadstate
                     elif e.errno == errno.ECHILD:
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 47c60f4..90b3c20 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -665,7 +665,6 @@
     _islink = staticmethod(_os.path.islink)
     _remove = staticmethod(_os.remove)
     _rmdir = staticmethod(_os.rmdir)
-    _os_error = OSError
     _warn = _warnings.warn
 
     def _rmtree(self, path):
@@ -675,16 +674,16 @@
             fullname = self._path_join(path, name)
             try:
                 isdir = self._isdir(fullname) and not self._islink(fullname)
-            except self._os_error:
+            except OSError:
                 isdir = False
             if isdir:
                 self._rmtree(fullname)
             else:
                 try:
                     self._remove(fullname)
-                except self._os_error:
+                except OSError:
                     pass
         try:
             self._rmdir(path)
-        except self._os_error:
+        except OSError:
             pass
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py
index af7c0b4..a370ed9 100644
--- a/Lib/test/sortperf.py
+++ b/Lib/test/sortperf.py
@@ -35,7 +35,7 @@
                 if fp:
                     try:
                         os.unlink(fn)
-                    except os.error:
+                    except OSError:
                         pass
         except IOError as msg:
             print("can't write", fn, ":", msg)
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index 3dd0d64..84a5e7b 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -82,7 +82,7 @@
         for fn in self.test_files:
             try:
                 os.remove(fn)
-            except os.error:
+            except OSError:
                 pass
         self.test_files[:] = []
 
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index f5193dc..2b8f096 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -188,7 +188,7 @@
 
             try:
                 dirname = os.getcwd()
-            except (AttributeError, os.error):
+            except (AttributeError, OSError):
                 dirname = os.curdir
 
             self.assertIn(dirname, cand)
@@ -924,7 +924,7 @@
         # (noted as part of Issue #10188)
         with tempfile.TemporaryDirectory() as nonexistent:
             pass
-        with self.assertRaises(os.error):
+        with self.assertRaises(OSError):
             tempfile.TemporaryDirectory(dir=nonexistent)
 
     def test_explicit_cleanup(self):
diff --git a/Lib/test/tf_inherit_check.py b/Lib/test/tf_inherit_check.py
index 92ebd95..afe50d2 100644
--- a/Lib/test/tf_inherit_check.py
+++ b/Lib/test/tf_inherit_check.py
@@ -11,7 +11,7 @@
 
     try:
         os.write(fd, b"blat")
-    except os.error:
+    except OSError:
         # Success -- could not write to fd.
         sys.exit(0)
     else: