From c602dc1c40f53b6fb30f4d25f90983b0fa183f9a Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 13 Jan 2014 01:57:26 +0100 Subject: [PATCH] modules like PyQt4.QtGui are now importable, because the import works again. used a code snippet from the old builtin plugin --- jedi/evaluate/compiled/__init__.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index b4fa3daa..d494571c 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -14,10 +14,6 @@ from jedi.evaluate.sys_path import get_sys_path from . import fake -# TODO -# unbound methods such as pyqtSignals have no __name__ -# if not hasattr(func, "__name__"): - class PyObject(Base): # comply with the parser start_pos = 0, 0 @@ -158,6 +154,20 @@ def load_module(path, name): # sometimes there are endings like `_sqlite3.cpython-32mu` name = re.sub(r'\..*', '', name) + if path: + dot_path = [] + p = path + # if path is not in sys.path, we need to make a well defined import + # like `from numpy.core import umath.` + while p and p not in sys.path: + p, sep, mod = p.rpartition(os.path.sep) + dot_path.insert(0, mod.partition('.')[0]) + if p: + name = ".".join(dot_path) + path = p + else: + path = os.path.dirname(path) + sys_path = get_sys_path() if path: sys_path.insert(0, path) @@ -172,7 +182,6 @@ def load_module(path, name): # directly. -> github issue #59 module = sys.modules[name] sys.path = temp - return PyObject(module)