Skip to content

Commit

Permalink
[3.6] replace dynamic import with 'exec' with importlib.import_module (
Browse files Browse the repository at this point in the history
…GH-5433) (GH-5440)

(cherry picked from commit 77526f0)
  • Loading branch information
benjaminp committed Jan 30, 2018
1 parent 05f91a4 commit 88fa79a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Lib/test/test_hashlib.py
Expand Up @@ -9,6 +9,7 @@
import array
from binascii import unhexlify
import hashlib
import importlib
import itertools
import os
import sys
Expand Down Expand Up @@ -86,11 +87,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()
Expand Down

0 comments on commit 88fa79a

Please sign in to comment.