Skip to content

Commit 55fe1ae

Browse files
bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)
1 parent fdbd011 commit 55fe1ae

36 files changed

+1530
-1530
lines changed

Include/ceval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
153153
154154
if (...premature_exit...) {
155155
Py_BLOCK_THREADS
156-
PyErr_SetFromErrno(PyExc_IOError);
156+
PyErr_SetFromErrno(PyExc_OSError);
157157
return NULL;
158158
}
159159
160160
An alternative is:
161161
162162
Py_BLOCK_THREADS
163163
if (...premature_exit...) {
164-
PyErr_SetFromErrno(PyExc_IOError);
164+
PyErr_SetFromErrno(PyExc_OSError);
165165
return NULL;
166166
}
167167
Py_UNBLOCK_THREADS

Lib/idlelib/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def idle_showwarning_subproc(
5252
try:
5353
file.write(idle_formatwarning(
5454
message, category, filename, lineno, line))
55-
except IOError:
55+
except OSError:
5656
pass # the file (probably stderr) is invalid - this warning gets lost.
5757

5858
_warnings_showwarning = None

Lib/importlib/_bootstrap_external.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,9 @@ def path_mtime(self, path):
689689
"""Optional method that returns the modification time (an int) for the
690690
specified path, where path is a str.
691691
692-
Raises IOError when the path cannot be handled.
692+
Raises OSError when the path cannot be handled.
693693
"""
694-
raise IOError
694+
raise OSError
695695

696696
def path_stats(self, path):
697697
"""Optional method returning a metadata dict for the specified path
@@ -702,7 +702,7 @@ def path_stats(self, path):
702702
- 'size' (optional) is the size in bytes of the source code.
703703
704704
Implementing this method allows the loader to read bytecode files.
705-
Raises IOError when the path cannot be handled.
705+
Raises OSError when the path cannot be handled.
706706
"""
707707
return {'mtime': self.path_mtime(path)}
708708

@@ -757,7 +757,7 @@ def get_code(self, fullname):
757757
else:
758758
try:
759759
st = self.path_stats(source_path)
760-
except IOError:
760+
except OSError:
761761
pass
762762
else:
763763
source_mtime = int(st['mtime'])

Lib/importlib/abc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ResourceLoader(Loader):
193193
def get_data(self, path):
194194
"""Abstract method which when implemented should return the bytes for
195195
the specified path. The path must be a str."""
196-
raise IOError
196+
raise OSError
197197

198198

199199
class InspectLoader(Loader):
@@ -315,7 +315,7 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
315315
def path_mtime(self, path):
316316
"""Return the (int) modification time for the path (str)."""
317317
if self.path_stats.__func__ is SourceLoader.path_stats:
318-
raise IOError
318+
raise OSError
319319
return int(self.path_stats(path)['mtime'])
320320

321321
def path_stats(self, path):
@@ -326,7 +326,7 @@ def path_stats(self, path):
326326
- 'size' (optional) is the size in bytes of the source code.
327327
"""
328328
if self.path_mtime.__func__ is SourceLoader.path_mtime:
329-
raise IOError
329+
raise OSError
330330
return {'mtime': self.path_mtime(path)}
331331

332332
def set_data(self, path, data):

Lib/mimetypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def enum_types(mimedb):
245245
while True:
246246
try:
247247
ctype = _winreg.EnumKey(mimedb, i)
248-
except EnvironmentError:
248+
except OSError:
249249
break
250250
else:
251251
if '\0' not in ctype:
@@ -259,13 +259,13 @@ def enum_types(mimedb):
259259
# Only check file extensions
260260
if not subkeyname.startswith("."):
261261
continue
262-
# raises EnvironmentError if no 'Content Type' value
262+
# raises OSError if no 'Content Type' value
263263
mimetype, datatype = _winreg.QueryValueEx(
264264
subkey, 'Content Type')
265265
if datatype != _winreg.REG_SZ:
266266
continue
267267
self.add_type(mimetype, subkeyname, strict)
268-
except EnvironmentError:
268+
except OSError:
269269
continue
270270

271271
def guess_type(url, strict=True):

Lib/pstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def do_add(self, line):
579579
if self.stats:
580580
try:
581581
self.stats.add(line)
582-
except IOError as e:
582+
except OSError as e:
583583
print("Failed to load statistics for %s: %s" % (line, e), file=self.stream)
584584
else:
585585
print("No statistics object is loaded.", file=self.stream)

Lib/site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def register_readline():
416416
'.python_history')
417417
try:
418418
readline.read_history_file(history)
419-
except IOError:
419+
except OSError:
420420
pass
421421
atexit.register(readline.write_history_file, history)
422422

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def system_must_validate_cert(f):
741741
def dec(*args, **kwargs):
742742
try:
743743
f(*args, **kwargs)
744-
except IOError as e:
744+
except OSError as e:
745745
if "CERTIFICATE_VERIFY_FAILED" in str(e):
746746
raise unittest.SkipTest("system does not contain "
747747
"necessary certificates")

Lib/unittest/test/test_assertions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def foo(self):
112112
a = A()
113113
wr = weakref.ref(a)
114114
try:
115-
raise IOError
116-
except IOError:
115+
raise OSError
116+
except OSError:
117117
raise ValueError
118118

119119
def test_functional(self):

Lib/urllib/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class URLError(OSError):
2020
# URLError is a sub-type of OSError, but it doesn't share any of
2121
# the implementation. need to override __init__ and __str__.
22-
# It sets self.args for compatibility with other EnvironmentError
22+
# It sets self.args for compatibility with other OSError
2323
# subclasses, but args doesn't have the typical format with errno in
2424
# slot 0 and strerror in slot 1. This may be better than nothing.
2525
def __init__(self, reason, filename=None):

0 commit comments

Comments
 (0)