From 260fbe80c5bd3611ae9e896a3c4714527667aece Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Thu, 4 Jul 2013 18:16:15 -0400 Subject: [PATCH] Issue #15767: Excise the remaining instances of ModuleNotFoundError --- Lib/stat.py | 2 +- Lib/test/regrtest.py | 16 ++++++++-------- Lib/test/support.py | 16 ++++++++-------- Lib/test/test___all__.py | 2 +- Lib/test/test_tarfile.py | 6 +++--- Lib/test/test_xmlrpc.py | 4 ++-- Lib/xmlrpc/server.py | 2 +- Lib/zipfile.py | 6 +++--- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Lib/stat.py b/Lib/stat.py index 0ea653b0142..3eecc3e0d34 100644 --- a/Lib/stat.py +++ b/Lib/stat.py @@ -151,5 +151,5 @@ def filemode(mode): # If available, use C implementation try: from _stat import * -except ModuleNotFoundError: +except ImportError: pass diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index bd816dd2d0d..aad0c62b21d 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -146,11 +146,11 @@ from inspect import isabstract try: import threading -except ModuleNotFoundError: +except ImportError: threading = None try: import multiprocessing.process -except ModuleNotFoundError: +except ImportError: multiprocessing = None @@ -180,7 +180,7 @@ for module in sys.modules.values(): if sys.platform == 'darwin': try: import resource - except ModuleNotFoundError: + except ImportError: pass else: soft, hard = resource.getrlimit(resource.RLIMIT_STACK) @@ -567,7 +567,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, if findleaks: try: import gc - except ModuleNotFoundError: + except ImportError: print('No GC available, disabling findleaks.') findleaks = False else: @@ -688,7 +688,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, if use_mp: try: from threading import Thread - except ModuleNotFoundError: + except ImportError: print("Multiprocess option requires thread support") sys.exit(2) from queue import Queue @@ -1399,7 +1399,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks): pic = sys.path_importer_cache.copy() try: import zipimport - except ModuleNotFoundError: + except ImportError: zdc = None # Run unmodified on platforms without zipimport support else: zdc = zipimport._zip_directory_cache.copy() @@ -1476,7 +1476,7 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs): sys.path_importer_cache.update(pic) try: import zipimport - except ModuleNotFoundError: + except ImportError: pass # Run unmodified on platforms without zipimport support else: zipimport._zip_directory_cache.clear() @@ -1513,7 +1513,7 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs): doctest.master = None try: import ctypes - except ModuleNotFoundError: + except ImportError: # Don't worry about resetting the cache if ctypes is not supported pass else: diff --git a/Lib/test/support.py b/Lib/test/support.py index 5b7cfc2d49d..d26e10cfc70 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -29,32 +29,32 @@ import _testcapi try: import _thread, threading -except ModuleNotFoundError: +except ImportError: _thread = None threading = None try: import multiprocessing.process -except ModuleNotFoundError: +except ImportError: multiprocessing = None try: import zlib -except ModuleNotFoundError: +except ImportError: zlib = None try: import gzip -except ModuleNotFoundError: +except ImportError: gzip = None try: import bz2 -except ModuleNotFoundError: +except ImportError: bz2 = None try: import lzma -except ModuleNotFoundError: +except ImportError: lzma = None __all__ = [ @@ -121,7 +121,7 @@ def import_module(name, deprecated=False, *, required_on=()): with _ignore_deprecated_imports(deprecated): try: return importlib.import_module(name) - except ModuleNotFoundError as msg: + except ImportError as msg: if sys.platform.startswith(tuple(required_on)): raise raise unittest.SkipTest(str(msg)) @@ -193,7 +193,7 @@ def import_fresh_module(name, fresh=(), blocked=(), deprecated=False): if not _save_and_block_module(blocked_name, orig_modules): names_to_remove.append(blocked_name) fresh_module = importlib.import_module(name) - except ModuleNotFoundError: + except ImportError: fresh_module = None finally: for orig_name, module in orig_modules.items(): diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index d0d7fa31c96..8cc285f70a5 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -75,7 +75,7 @@ class AllTest(unittest.TestCase): try: import rlcompleter import locale - except ModuleNotFoundError: + except ImportError: pass else: locale.setlocale(locale.LC_CTYPE, 'C') diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index f3cb464f57a..2f2bf6b8bec 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -12,15 +12,15 @@ from test import support # Check for our compression modules. try: import gzip -except ModuleNotFoundError: +except ImportError: gzip = None try: import bz2 -except ModuleNotFoundError: +except ImportError: bz2 = None try: import lzma -except ModuleNotFoundError: +except ImportError: lzma = None def md5sum(data): diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 99be297340b..31d735ebbf7 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -15,11 +15,11 @@ from test import support try: import gzip -except ModuleNotFoundError: +except ImportError: gzip = None try: import threading -except ModuleNotFoundError: +except ImportError: threading = None alist = [{'astring': 'foo@bar.baz.spam', diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index 80233e48143..54e172670b1 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -116,7 +116,7 @@ import inspect import traceback try: import fcntl -except ModuleNotFoundError: +except ImportError: fcntl = None def resolve_dotted_attribute(obj, attr, allow_dotted_names=True): diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 4099930b339..7d6591fadf1 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -18,18 +18,18 @@ import binascii try: import zlib # We may need its compression method crc32 = zlib.crc32 -except ModuleNotFoundError: +except ImportError: zlib = None crc32 = binascii.crc32 try: import bz2 # We may need its compression method -except ModuleNotFoundError: +except ImportError: bz2 = None try: import lzma # We may need its compression method -except ModuleNotFoundError: +except ImportError: lzma = None __all__ = ["BadZipFile", "BadZipfile", "error",