Reformat and move imports to top level.

This commit is contained in:
Matthias Bussonnier
2020-08-03 08:24:24 -07:00
parent 20be4f02c8
commit a9e2cd5a74
2 changed files with 10 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import inspect
import types
import traceback
import sys
import operator as op
from collections import namedtuple
@@ -117,13 +118,18 @@ def load_module(inference_state, dotted_name, sys_path):
__import__(dotted_name)
except ImportError:
# If a module is "corrupt" or not really a Python module or whatever.
warnings.warn('Module %s not importable in path %s.' % (dotted_name, sys_path), UserWarning)
warnings.warn(
"Module %s not importable in path %s." % (dotted_name, sys_path),
UserWarning,
stacklevel=2,
)
return None
except Exception:
# Since __import__ pretty much makes code execution possible, just
# catch any error here and print it.
import traceback
warnings.warn("Cannot import:\n%s" % traceback.format_exc(), UserWarning)
warnings.warn(
"Cannot import:\n%s" % traceback.format_exc(), UserWarning, stacklevel=2
)
return None
finally:
sys.path = temp