Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3438fa4

Browse files
committed
Get rig of EnvironmentError (#16705)
1 parent 6eda46d commit 3438fa4

16 files changed

Lines changed: 34 additions & 35 deletions

Lib/compileall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def main():
209209
with (sys.stdin if args.flist=='-' else open(args.flist)) as f:
210210
for line in f:
211211
compile_dests.append(line.strip())
212-
except EnvironmentError:
212+
except OSError:
213213
print("Error reading file list {}".format(args.flist))
214214
return False
215215

Lib/getpass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def unix_getpass(prompt='Password: ', stream=None):
4747
input = tty
4848
if not stream:
4949
stream = tty
50-
except EnvironmentError as e:
50+
except OSError as e:
5151
# If that fails, see if stdin can be controlled.
5252
try:
5353
fd = sys.stdin.fileno()

Lib/mimetypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def enum_types(mimedb):
243243
while True:
244244
try:
245245
ctype = _winreg.EnumKey(mimedb, i)
246-
except EnvironmentError:
246+
except OSError:
247247
break
248248
else:
249249
yield ctype
@@ -256,7 +256,7 @@ def enum_types(mimedb):
256256
with _winreg.OpenKey(mimedb, ctype) as key:
257257
suffix, datatype = _winreg.QueryValueEx(key,
258258
'Extension')
259-
except EnvironmentError:
259+
except OSError:
260260
continue
261261
if datatype != _winreg.REG_SZ:
262262
continue

Lib/shutil.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
"ignore_patterns", "chown", "which"]
4040
# disk_usage is added later, if available on the platform
4141

42-
class Error(EnvironmentError):
42+
class Error(OSError):
4343
pass
4444

4545
class SameFileError(Error):
4646
"""Raised when source and destination are the same file."""
4747

48-
class SpecialFileError(EnvironmentError):
48+
class SpecialFileError(OSError):
4949
"""Raised when trying to do a kind of operation (e.g. copying) which is
5050
not supported on a special file (e.g. a named pipe)"""
5151

52-
class ExecError(EnvironmentError):
52+
class ExecError(OSError):
5353
"""Raised when a command could not be executed"""
5454

55-
class ReadError(EnvironmentError):
55+
class ReadError(OSError):
5656
"""Raised when an archive cannot be read"""
5757

5858
class RegistryError(Exception):
@@ -329,7 +329,7 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
329329
# continue with other files
330330
except Error as err:
331331
errors.extend(err.args[0])
332-
except EnvironmentError as why:
332+
except OSError as why:
333333
errors.append((srcname, dstname, str(why)))
334334
try:
335335
copystat(src, dst)

Lib/subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def __init__(self, args, bufsize=0, executable=None,
819819
for f in filter(None, (self.stdin, self.stdout, self.stderr)):
820820
try:
821821
f.close()
822-
except EnvironmentError:
822+
except OSError:
823823
pass # Ignore EBADF or other errors.
824824

825825
# Make sure the child pipes are closed as well.
@@ -833,7 +833,7 @@ def __init__(self, args, bufsize=0, executable=None,
833833
for fd in to_close:
834834
try:
835835
os.close(fd)
836-
except EnvironmentError:
836+
except OSError:
837837
pass
838838

839839
raise

Lib/tarfile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ def extract(self, member, path="", set_attrs=True):
20222022
try:
20232023
self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
20242024
set_attrs=set_attrs)
2025-
except EnvironmentError as e:
2025+
except OSError as e:
20262026
if self.errorlevel > 0:
20272027
raise
20282028
else:
@@ -2212,7 +2212,7 @@ def chown(self, tarinfo, targetpath):
22122212
os.lchown(targetpath, u, g)
22132213
else:
22142214
os.chown(targetpath, u, g)
2215-
except EnvironmentError as e:
2215+
except OSError as e:
22162216
raise ExtractError("could not change owner")
22172217

22182218
def chmod(self, tarinfo, targetpath):
@@ -2221,7 +2221,7 @@ def chmod(self, tarinfo, targetpath):
22212221
if hasattr(os, 'chmod'):
22222222
try:
22232223
os.chmod(targetpath, tarinfo.mode)
2224-
except EnvironmentError as e:
2224+
except OSError as e:
22252225
raise ExtractError("could not change mode")
22262226

22272227
def utime(self, tarinfo, targetpath):
@@ -2231,7 +2231,7 @@ def utime(self, tarinfo, targetpath):
22312231
return
22322232
try:
22332233
os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
2234-
except EnvironmentError as e:
2234+
except OSError as e:
22352235
raise ExtractError("could not change modification time")
22362236

22372237
#--------------------------------------------------------------------------

Lib/test/test_exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ def testAttributes(self):
255255
'errno' : 'foo', 'strerror' : 'bar'}),
256256
(IOError, ('foo', 'bar', 'baz', 'quux'),
257257
{'args' : ('foo', 'bar', 'baz', 'quux')}),
258-
(EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'),
258+
(OSError, ('errnoStr', 'strErrorStr', 'filenameStr'),
259259
{'args' : ('errnoStr', 'strErrorStr'),
260260
'strerror' : 'strErrorStr', 'errno' : 'errnoStr',
261261
'filename' : 'filenameStr'}),
262-
(EnvironmentError, (1, 'strErrorStr', 'filenameStr'),
262+
(OSError, (1, 'strErrorStr', 'filenameStr'),
263263
{'args' : (1, 'strErrorStr'), 'errno' : 1,
264264
'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}),
265265
(SyntaxError, (), {'msg' : None, 'text' : None,
@@ -409,7 +409,7 @@ def testChainingAttrs(self):
409409
self.assertIsNone(e.__context__)
410410
self.assertIsNone(e.__cause__)
411411

412-
class MyException(EnvironmentError):
412+
class MyException(OSError):
413413
pass
414414

415415
e = MyException()

Lib/test/test_fileio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def testAbles(self):
285285
if sys.platform != "win32":
286286
try:
287287
f = _FileIO("/dev/tty", "a")
288-
except EnvironmentError:
288+
except OSError:
289289
# When run in a cron job there just aren't any
290290
# ttys, so skip the test. This also handles other
291291
# OS'es that don't support /dev/tty.

Lib/test/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ def cleanup_fds():
28252825
for fd in fds:
28262826
try:
28272827
os.close(fd)
2828-
except EnvironmentError as e:
2828+
except OSError as e:
28292829
if e.errno != errno.EBADF:
28302830
raise
28312831
self.addCleanup(cleanup_fds)

Lib/test/test_signal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def exit_subprocess():
3333
def ignoring_eintr(__func, *args, **kwargs):
3434
try:
3535
return __func(*args, **kwargs)
36-
except EnvironmentError as e:
36+
except OSError as e:
3737
if e.errno != errno.EINTR:
3838
raise
3939
return None

0 commit comments

Comments
 (0)