forked from VimPlug/jedi
Directly load modules if possible, with this it's not necessary anymore to use dotted_from_fs_path, also fixes #1013.
This commit is contained in:
@@ -5,11 +5,9 @@ from textwrap import dedent
|
||||
import operator as op
|
||||
from collections import namedtuple
|
||||
|
||||
from jedi import debug
|
||||
from jedi._compatibility import unicode, is_py3, is_py34, builtins, \
|
||||
py_version, force_unicode, print_to_stderr
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
from jedi.evaluate.utils import dotted_from_fs_path
|
||||
|
||||
|
||||
MethodDescriptorType = type(str.replace)
|
||||
@@ -137,20 +135,13 @@ def create_access(evaluator, obj):
|
||||
return evaluator.compiled_subprocess.get_or_create_access_handle(obj)
|
||||
|
||||
|
||||
def load_module(evaluator, path=None, name=None, sys_path=None):
|
||||
if sys_path is None:
|
||||
sys_path = list(evaluator.get_sys_path())
|
||||
if path is not None:
|
||||
dotted_path = dotted_from_fs_path(path, sys_path=sys_path)
|
||||
else:
|
||||
dotted_path = name
|
||||
|
||||
def load_module(evaluator, dotted_name, sys_path):
|
||||
temp, sys.path = sys.path, sys_path
|
||||
try:
|
||||
__import__(dotted_path)
|
||||
__import__(dotted_name)
|
||||
except ImportError:
|
||||
# If a module is "corrupt" or not really a Python module or whatever.
|
||||
print_to_stderr('Module %s not importable in path %s.' % (dotted_path, path))
|
||||
print_to_stderr('Module %s not importable.' % dotted_name)
|
||||
return None
|
||||
except Exception:
|
||||
# Since __import__ pretty much makes code execution possible, just
|
||||
@@ -163,7 +154,7 @@ def load_module(evaluator, path=None, name=None, sys_path=None):
|
||||
|
||||
# Just access the cache after import, because of #59 as well as the very
|
||||
# complicated import structure of Python.
|
||||
module = sys.modules[dotted_path]
|
||||
module = sys.modules[dotted_name]
|
||||
return create_access_path(evaluator, module)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user