Commit e2bc5bcf authored by Brett Cannon's avatar Brett Cannon

Issue #18200: Update the stdlib (except tests) to use

ModuleNotFoundError.
parent 38c067b7
...@@ -9,7 +9,7 @@ import sys ...@@ -9,7 +9,7 @@ import sys
try: try:
import zipfile import zipfile
except ImportError: except ModuleNotFoundError:
zipfile = None zipfile = None
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Contains CCompiler, an abstract base class that defines the interface Contains CCompiler, an abstract base class that defines the interface
for the Distutils compiler abstraction model.""" for the Distutils compiler abstraction model."""
import sys, os, re import importlib, sys, os, re
from distutils.errors import * from distutils.errors import *
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils.file_util import move_file from distutils.file_util import move_file
...@@ -1013,10 +1013,9 @@ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0): ...@@ -1013,10 +1013,9 @@ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
try: try:
module_name = "distutils." + module_name module_name = "distutils." + module_name
__import__ (module_name) module = importlib.import_module(module_name)
module = sys.modules[module_name]
klass = vars(module)[class_name] klass = vars(module)[class_name]
except ImportError: except ModuleNotFoundError:
raise DistutilsModuleError( raise DistutilsModuleError(
"can't compile C/C++ code: unable to load module '%s'" % \ "can't compile C/C++ code: unable to load module '%s'" % \
module_name) module_name)
......
...@@ -4,11 +4,11 @@ Provides the Distribution class, which represents the module distribution ...@@ -4,11 +4,11 @@ Provides the Distribution class, which represents the module distribution
being built/installed/distributed. being built/installed/distributed.
""" """
import sys, os, re import importlib, sys, os, re
try: try:
import warnings import warnings
except ImportError: except ModuleNotFoundError:
warnings = None warnings = None
from distutils.errors import * from distutils.errors import *
...@@ -788,9 +788,8 @@ Common commands: (see '--help-commands' for more) ...@@ -788,9 +788,8 @@ Common commands: (see '--help-commands' for more)
klass_name = command klass_name = command
try: try:
__import__ (module_name) module = importlib.import_module(module_name)
module = sys.modules[module_name] except ModuleNotFoundError:
except ImportError:
continue continue
try: try:
......
...@@ -28,7 +28,7 @@ try: ...@@ -28,7 +28,7 @@ try:
RegEnumValue = winreg.EnumValue RegEnumValue = winreg.EnumValue
RegError = winreg.error RegError = winreg.error
except ImportError: except ModuleNotFoundError:
try: try:
import win32api import win32api
import win32con import win32con
...@@ -39,7 +39,7 @@ except ImportError: ...@@ -39,7 +39,7 @@ except ImportError:
RegEnumKey = win32api.RegEnumKey RegEnumKey = win32api.RegEnumKey
RegEnumValue = win32api.RegEnumValue RegEnumValue = win32api.RegEnumValue
RegError = win32api.error RegError = win32api.error
except ImportError: except ModuleNotFoundError:
log.info("Warning: Can't read registry to find the " log.info("Warning: Can't read registry to find the "
"necessary compiler setting\n" "necessary compiler setting\n"
"Make sure that Python modules winreg, " "Make sure that Python modules winreg, "
......
...@@ -388,7 +388,7 @@ def byte_compile (py_files, ...@@ -388,7 +388,7 @@ def byte_compile (py_files,
try: try:
from tempfile import mkstemp from tempfile import mkstemp
(script_fd, script_name) = mkstemp(".py") (script_fd, script_name) = mkstemp(".py")
except ImportError: except ModuleNotFoundError:
from tempfile import mktemp from tempfile import mktemp
(script_fd, script_name) = None, mktemp(".py") (script_fd, script_name) = None, mktemp(".py")
log.info("writing byte-compilation script '%s'", script_name) log.info("writing byte-compilation script '%s'", script_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment