diff --git a/functions.py b/functions.py index e80a592f..089fccea 100644 --- a/functions.py +++ b/functions.py @@ -277,13 +277,18 @@ def goto(source, line, column, source_path): new_names = [] for n in names: par = n.parent + # This is a special case: If the Import is "virtual" (which + # means the position is not defined), follow those modules. if isinstance(par, parsing.Import) and not par.start_pos[0]: - # this is a special case: If + module_count = 0 for scope in imports.ImportPath(par).follow(): if isinstance(scope, parsing.Import): temp = scope.get_defined_names() new_names += remove_unreal_imports(temp) - elif isinstance(scope, parsing.Module): + elif isinstance(scope, parsing.Module) \ + and not module_count: + # only first module (others are star imports) + module_count += 1 new_names.append(scope.get_module_name(n.names)) else: new_names.append(n) diff --git a/imports.py b/imports.py index 02beb65e..d85f608d 100644 --- a/imports.py +++ b/imports.py @@ -115,21 +115,15 @@ class ImportPath(object): def follow_str(ns, string): debug.dbg('follow_module', ns, string) if ns: - try: - return imp.find_module(string, [ns[1]]) - except ImportError: - return imp.find_module(string, builtin.module_find_path) + return imp.find_module(string, [ns[1]]) else: path = None debug.dbg('search_module', string, path, self.file_path) - #sys.path, temp = builtin.module_find_path, sys.path - try: - i = imp.find_module(string, builtin.module_find_path) - except ImportError: - # find builtins (ommit path): - #i = imp.find_module(string) - raise - #sys.path = temp + # Override the sys.path. It works only good that way. + # Injecting the path directly into `find_module` did not work. + sys.path, temp = builtin.module_find_path, sys.path + i = imp.find_module(string) + sys.path = temp return i # TODO handle relative paths - they are included in the import object diff --git a/test/completion/import_tree/random.py b/test/completion/import_tree/random.py new file mode 100644 index 00000000..a63ed059 --- /dev/null +++ b/test/completion/import_tree/random.py @@ -0,0 +1,4 @@ +""" +Here because random is also a builtin module. +""" +a = set diff --git a/test/completion/thirdparty/PyQt4.py b/test/completion/thirdparty/PyQt4_.py similarity index 100% rename from test/completion/thirdparty/PyQt4.py rename to test/completion/thirdparty/PyQt4_.py diff --git a/test/completion/thirdparty/PySide_.py b/test/completion/thirdparty/PySide_.py new file mode 100644 index 00000000..69c37d82 --- /dev/null +++ b/test/completion/thirdparty/PySide_.py @@ -0,0 +1,9 @@ +from PySide import QtCore +from PySide import QtGui + +##? ['QEvent'] +QtCore.QEvent + +##? [] +QtGui.QButton + diff --git a/test/completion/thirdparty/django.py b/test/completion/thirdparty/django_.py similarity index 100% rename from test/completion/thirdparty/django.py rename to test/completion/thirdparty/django_.py diff --git a/test/completion/thirdparty/jedi.py b/test/completion/thirdparty/jedi_.py similarity index 97% rename from test/completion/thirdparty/jedi.py rename to test/completion/thirdparty/jedi_.py index 56cd815a..412a7d9f 100644 --- a/test/completion/thirdparty/jedi.py +++ b/test/completion/thirdparty/jedi_.py @@ -14,7 +14,7 @@ scopes, path, dot, like = \ source_path, True) # has problems with that (sometimes) very deep nesting. -#? set() list() +#? set() el = scopes. # get_names_for_scope is also recursion stuff diff --git a/test/completion/thirdparty/pylab.py b/test/completion/thirdparty/pylab_.py similarity index 100% rename from test/completion/thirdparty/pylab.py rename to test/completion/thirdparty/pylab_.py diff --git a/test/run.py b/test/run.py index 50f7a097..9242bdc1 100755 --- a/test/run.py +++ b/test/run.py @@ -179,7 +179,9 @@ def test_dir(completion_test_dir, third_party=False): if f_name.endswith(".py"): if third_party: try: - __import__(f_name.replace('.py', '')) + # there is always an underline at the end. + # It looks like: completion/thirdparty/pylab_.py + __import__(f_name.replace('_.py', '')) except ImportError: summary.append('Thirdparty-Library %s not found.' % f_name)