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

Skip to content

Commit 77526f0

Browse files
benjaminpgpshead
authored andcommitted
replace dynamic import with 'exec' with importlib.import_module (#5433)
1 parent 7f8bfc9 commit 77526f0

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Lib/test/test_hashlib.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import array
1010
from binascii import unhexlify
1111
import hashlib
12+
import importlib
1213
import itertools
1314
import os
1415
import sys
@@ -83,11 +84,11 @@ class HashLibTestCase(unittest.TestCase):
8384
def _conditional_import_module(self, module_name):
8485
"""Import a module and return a reference to it or None on failure."""
8586
try:
86-
exec('import '+module_name)
87-
except ImportError as error:
87+
return importlib.import_module(module_name)
88+
except ModuleNotFoundError as error:
8889
if self._warn_on_extension_import:
8990
warnings.warn('Did a C extension fail to compile? %s' % error)
90-
return locals().get(module_name)
91+
return None
9192

9293
def __init__(self, *args, **kwargs):
9394
algorithms = set()

0 commit comments

Comments
 (0)