Issue #15767: Excise the remaining instances of ModuleNotFoundError

This commit is contained in:
Brett Cannon 2013-07-04 18:16:15 -04:00
parent 3dfd23245b
commit 260fbe80c5
8 changed files with 27 additions and 27 deletions

View File

@ -151,5 +151,5 @@ def filemode(mode):
# If available, use C implementation # If available, use C implementation
try: try:
from _stat import * from _stat import *
except ModuleNotFoundError: except ImportError:
pass pass

View File

@ -146,11 +146,11 @@ from inspect import isabstract
try: try:
import threading import threading
except ModuleNotFoundError: except ImportError:
threading = None threading = None
try: try:
import multiprocessing.process import multiprocessing.process
except ModuleNotFoundError: except ImportError:
multiprocessing = None multiprocessing = None
@ -180,7 +180,7 @@ for module in sys.modules.values():
if sys.platform == 'darwin': if sys.platform == 'darwin':
try: try:
import resource import resource
except ModuleNotFoundError: except ImportError:
pass pass
else: else:
soft, hard = resource.getrlimit(resource.RLIMIT_STACK) soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
@ -567,7 +567,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
if findleaks: if findleaks:
try: try:
import gc import gc
except ModuleNotFoundError: except ImportError:
print('No GC available, disabling findleaks.') print('No GC available, disabling findleaks.')
findleaks = False findleaks = False
else: else:
@ -688,7 +688,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
if use_mp: if use_mp:
try: try:
from threading import Thread from threading import Thread
except ModuleNotFoundError: except ImportError:
print("Multiprocess option requires thread support") print("Multiprocess option requires thread support")
sys.exit(2) sys.exit(2)
from queue import Queue from queue import Queue
@ -1399,7 +1399,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
pic = sys.path_importer_cache.copy() pic = sys.path_importer_cache.copy()
try: try:
import zipimport import zipimport
except ModuleNotFoundError: except ImportError:
zdc = None # Run unmodified on platforms without zipimport support zdc = None # Run unmodified on platforms without zipimport support
else: else:
zdc = zipimport._zip_directory_cache.copy() 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) sys.path_importer_cache.update(pic)
try: try:
import zipimport import zipimport
except ModuleNotFoundError: except ImportError:
pass # Run unmodified on platforms without zipimport support pass # Run unmodified on platforms without zipimport support
else: else:
zipimport._zip_directory_cache.clear() zipimport._zip_directory_cache.clear()
@ -1513,7 +1513,7 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
doctest.master = None doctest.master = None
try: try:
import ctypes import ctypes
except ModuleNotFoundError: except ImportError:
# Don't worry about resetting the cache if ctypes is not supported # Don't worry about resetting the cache if ctypes is not supported
pass pass
else: else:

View File

@ -29,32 +29,32 @@ import _testcapi
try: try:
import _thread, threading import _thread, threading
except ModuleNotFoundError: except ImportError:
_thread = None _thread = None
threading = None threading = None
try: try:
import multiprocessing.process import multiprocessing.process
except ModuleNotFoundError: except ImportError:
multiprocessing = None multiprocessing = None
try: try:
import zlib import zlib
except ModuleNotFoundError: except ImportError:
zlib = None zlib = None
try: try:
import gzip import gzip
except ModuleNotFoundError: except ImportError:
gzip = None gzip = None
try: try:
import bz2 import bz2
except ModuleNotFoundError: except ImportError:
bz2 = None bz2 = None
try: try:
import lzma import lzma
except ModuleNotFoundError: except ImportError:
lzma = None lzma = None
__all__ = [ __all__ = [
@ -121,7 +121,7 @@ def import_module(name, deprecated=False, *, required_on=()):
with _ignore_deprecated_imports(deprecated): with _ignore_deprecated_imports(deprecated):
try: try:
return importlib.import_module(name) return importlib.import_module(name)
except ModuleNotFoundError as msg: except ImportError as msg:
if sys.platform.startswith(tuple(required_on)): if sys.platform.startswith(tuple(required_on)):
raise raise
raise unittest.SkipTest(str(msg)) 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): if not _save_and_block_module(blocked_name, orig_modules):
names_to_remove.append(blocked_name) names_to_remove.append(blocked_name)
fresh_module = importlib.import_module(name) fresh_module = importlib.import_module(name)
except ModuleNotFoundError: except ImportError:
fresh_module = None fresh_module = None
finally: finally:
for orig_name, module in orig_modules.items(): for orig_name, module in orig_modules.items():

View File

@ -75,7 +75,7 @@ class AllTest(unittest.TestCase):
try: try:
import rlcompleter import rlcompleter
import locale import locale
except ModuleNotFoundError: except ImportError:
pass pass
else: else:
locale.setlocale(locale.LC_CTYPE, 'C') locale.setlocale(locale.LC_CTYPE, 'C')

View File

@ -12,15 +12,15 @@ from test import support
# Check for our compression modules. # Check for our compression modules.
try: try:
import gzip import gzip
except ModuleNotFoundError: except ImportError:
gzip = None gzip = None
try: try:
import bz2 import bz2
except ModuleNotFoundError: except ImportError:
bz2 = None bz2 = None
try: try:
import lzma import lzma
except ModuleNotFoundError: except ImportError:
lzma = None lzma = None
def md5sum(data): def md5sum(data):

View File

@ -15,11 +15,11 @@ from test import support
try: try:
import gzip import gzip
except ModuleNotFoundError: except ImportError:
gzip = None gzip = None
try: try:
import threading import threading
except ModuleNotFoundError: except ImportError:
threading = None threading = None
alist = [{'astring': 'foo@bar.baz.spam', alist = [{'astring': 'foo@bar.baz.spam',

View File

@ -116,7 +116,7 @@ import inspect
import traceback import traceback
try: try:
import fcntl import fcntl
except ModuleNotFoundError: except ImportError:
fcntl = None fcntl = None
def resolve_dotted_attribute(obj, attr, allow_dotted_names=True): def resolve_dotted_attribute(obj, attr, allow_dotted_names=True):

View File

@ -18,18 +18,18 @@ import binascii
try: try:
import zlib # We may need its compression method import zlib # We may need its compression method
crc32 = zlib.crc32 crc32 = zlib.crc32
except ModuleNotFoundError: except ImportError:
zlib = None zlib = None
crc32 = binascii.crc32 crc32 = binascii.crc32
try: try:
import bz2 # We may need its compression method import bz2 # We may need its compression method
except ModuleNotFoundError: except ImportError:
bz2 = None bz2 = None
try: try:
import lzma # We may need its compression method import lzma # We may need its compression method
except ModuleNotFoundError: except ImportError:
lzma = None lzma = None
__all__ = ["BadZipFile", "BadZipfile", "error", __all__ = ["BadZipFile", "BadZipfile", "error",