bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index afa9744..12c339f 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -52,7 +52,7 @@
try:
file.write(idle_formatwarning(
message, category, filename, lineno, line))
- except IOError:
+ except OSError:
pass # the file (probably stderr) is invalid - this warning gets lost.
_warnings_showwarning = None
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index ec528b2..3235404 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -689,9 +689,9 @@
"""Optional method that returns the modification time (an int) for the
specified path, where path is a str.
- Raises IOError when the path cannot be handled.
+ Raises OSError when the path cannot be handled.
"""
- raise IOError
+ raise OSError
def path_stats(self, path):
"""Optional method returning a metadata dict for the specified path
@@ -702,7 +702,7 @@
- 'size' (optional) is the size in bytes of the source code.
Implementing this method allows the loader to read bytecode files.
- Raises IOError when the path cannot be handled.
+ Raises OSError when the path cannot be handled.
"""
return {'mtime': self.path_mtime(path)}
@@ -757,7 +757,7 @@
else:
try:
st = self.path_stats(source_path)
- except IOError:
+ except OSError:
pass
else:
source_mtime = int(st['mtime'])
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 661bd76..d7cadf2 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -193,7 +193,7 @@
def get_data(self, path):
"""Abstract method which when implemented should return the bytes for
the specified path. The path must be a str."""
- raise IOError
+ raise OSError
class InspectLoader(Loader):
@@ -315,7 +315,7 @@
def path_mtime(self, path):
"""Return the (int) modification time for the path (str)."""
if self.path_stats.__func__ is SourceLoader.path_stats:
- raise IOError
+ raise OSError
return int(self.path_stats(path)['mtime'])
def path_stats(self, path):
@@ -326,7 +326,7 @@
- 'size' (optional) is the size in bytes of the source code.
"""
if self.path_mtime.__func__ is SourceLoader.path_mtime:
- raise IOError
+ raise OSError
return {'mtime': self.path_mtime(path)}
def set_data(self, path, data):
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 9a88680..3d68694 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -245,7 +245,7 @@
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
- except EnvironmentError:
+ except OSError:
break
else:
if '\0' not in ctype:
@@ -259,13 +259,13 @@
# Only check file extensions
if not subkeyname.startswith("."):
continue
- # raises EnvironmentError if no 'Content Type' value
+ # raises OSError if no 'Content Type' value
mimetype, datatype = _winreg.QueryValueEx(
subkey, 'Content Type')
if datatype != _winreg.REG_SZ:
continue
self.add_type(mimetype, subkeyname, strict)
- except EnvironmentError:
+ except OSError:
continue
def guess_type(url, strict=True):
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 2c5bf98..b8bcfb2 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -579,7 +579,7 @@
if self.stats:
try:
self.stats.add(line)
- except IOError as e:
+ except OSError as e:
print("Failed to load statistics for %s: %s" % (line, e), file=self.stream)
else:
print("No statistics object is loaded.", file=self.stream)
diff --git a/Lib/site.py b/Lib/site.py
index 4f96ca9..8797938 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -416,7 +416,7 @@
'.python_history')
try:
readline.read_history_file(history)
- except IOError:
+ except OSError:
pass
atexit.register(readline.write_history_file, history)
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 6658ece..21d8f2c 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -741,7 +741,7 @@
def dec(*args, **kwargs):
try:
f(*args, **kwargs)
- except IOError as e:
+ except OSError as e:
if "CERTIFICATE_VERIFY_FAILED" in str(e):
raise unittest.SkipTest("system does not contain "
"necessary certificates")
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py
index 1b0e833..31565da 100644
--- a/Lib/unittest/test/test_assertions.py
+++ b/Lib/unittest/test/test_assertions.py
@@ -112,8 +112,8 @@
a = A()
wr = weakref.ref(a)
try:
- raise IOError
- except IOError:
+ raise OSError
+ except OSError:
raise ValueError
def test_functional(self):
diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py
index 851515b..8cd901f 100644
--- a/Lib/urllib/error.py
+++ b/Lib/urllib/error.py
@@ -19,7 +19,7 @@
class URLError(OSError):
# URLError is a sub-type of OSError, but it doesn't share any of
# the implementation. need to override __init__ and __str__.
- # It sets self.args for compatibility with other EnvironmentError
+ # It sets self.args for compatibility with other OSError
# subclasses, but args doesn't have the typical format with errno in
# slot 0 and strerror in slot 1. This may be better than nothing.
def __init__(self, reason, filename=None):