mirror of
https://github.com/python/cpython.git
synced 2025-10-02 13:22:19 +00:00
[3.6] replace dynamic import with 'exec' with importlib.import_module (GH-5433) (GH-5440)
(cherry picked from commit 77526f05fa
)
This commit is contained in:
parent
05f91a42cd
commit
88fa79a10a
1 changed files with 4 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
||||||
import array
|
import array
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import importlib
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -86,11 +87,11 @@ class HashLibTestCase(unittest.TestCase):
|
||||||
def _conditional_import_module(self, module_name):
|
def _conditional_import_module(self, module_name):
|
||||||
"""Import a module and return a reference to it or None on failure."""
|
"""Import a module and return a reference to it or None on failure."""
|
||||||
try:
|
try:
|
||||||
exec('import '+module_name)
|
return importlib.import_module(module_name)
|
||||||
except ImportError as error:
|
except ModuleNotFoundError as error:
|
||||||
if self._warn_on_extension_import:
|
if self._warn_on_extension_import:
|
||||||
warnings.warn('Did a C extension fail to compile? %s' % error)
|
warnings.warn('Did a C extension fail to compile? %s' % error)
|
||||||
return locals().get(module_name)
|
return None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
algorithms = set()
|
algorithms = set()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue