diff options
author | Benjamin Peterson <benjamin@python.org> | 2018-01-30 02:03:01 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2018-01-30 02:03:01 (GMT) |
commit | 77526f05fa788d6fb12f2121fe6b96c130d9b717 (patch) | |
tree | d5e6acd2298c7f55893d1eb495da941c89385d22 /Lib/test/test_hashlib.py | |
parent | 7f8bfc9b9a8381ddb768421b5dd5cbd970266190 (diff) | |
download | cpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.zip cpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.tar.gz cpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.tar.bz2 |
replace dynamic import with 'exec' with importlib.import_module (#5433)
Diffstat (limited to 'Lib/test/test_hashlib.py')
-rw-r--r-- | Lib/test/test_hashlib.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index e4e5280..15fc22b 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -9,6 +9,7 @@ import array from binascii import unhexlify import hashlib +import importlib import itertools import os import sys @@ -83,11 +84,11 @@ class HashLibTestCase(unittest.TestCase): def _conditional_import_module(self, module_name): """Import a module and return a reference to it or None on failure.""" try: - exec('import '+module_name) - except ImportError as error: + return importlib.import_module(module_name) + except ModuleNotFoundError as error: if self._warn_on_extension_import: warnings.warn('Did a C extension fail to compile? %s' % error) - return locals().get(module_name) + return None def __init__(self, *args, **kwargs): algorithms = set() |