imports are now fully functional

This commit is contained in:
David Halter
2012-08-03 13:00:44 +02:00
parent a9fbb2edce
commit 639457b9ec
9 changed files with 30 additions and 16 deletions

View File

@@ -277,13 +277,18 @@ def goto(source, line, column, source_path):
new_names = [] new_names = []
for n in names: for n in names:
par = n.parent 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]: 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(): for scope in imports.ImportPath(par).follow():
if isinstance(scope, parsing.Import): if isinstance(scope, parsing.Import):
temp = scope.get_defined_names() temp = scope.get_defined_names()
new_names += remove_unreal_imports(temp) 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)) new_names.append(scope.get_module_name(n.names))
else: else:
new_names.append(n) new_names.append(n)

View File

@@ -115,21 +115,15 @@ class ImportPath(object):
def follow_str(ns, string): def follow_str(ns, string):
debug.dbg('follow_module', ns, string) debug.dbg('follow_module', ns, string)
if ns: if ns:
try: return imp.find_module(string, [ns[1]])
return imp.find_module(string, [ns[1]])
except ImportError:
return imp.find_module(string, builtin.module_find_path)
else: else:
path = None path = None
debug.dbg('search_module', string, path, self.file_path) debug.dbg('search_module', string, path, self.file_path)
#sys.path, temp = builtin.module_find_path, sys.path # Override the sys.path. It works only good that way.
try: # Injecting the path directly into `find_module` did not work.
i = imp.find_module(string, builtin.module_find_path) sys.path, temp = builtin.module_find_path, sys.path
except ImportError: i = imp.find_module(string)
# find builtins (ommit path): sys.path = temp
#i = imp.find_module(string)
raise
#sys.path = temp
return i return i
# TODO handle relative paths - they are included in the import object # TODO handle relative paths - they are included in the import object

View File

@@ -0,0 +1,4 @@
"""
Here because random is also a builtin module.
"""
a = set

9
test/completion/thirdparty/PySide_.py vendored Normal file
View File

@@ -0,0 +1,9 @@
from PySide import QtCore
from PySide import QtGui
##? ['QEvent']
QtCore.QEvent
##? []
QtGui.QButton

View File

@@ -14,7 +14,7 @@ scopes, path, dot, like = \
source_path, True) source_path, True)
# has problems with that (sometimes) very deep nesting. # has problems with that (sometimes) very deep nesting.
#? set() list() #? set()
el = scopes. el = scopes.
# get_names_for_scope is also recursion stuff # get_names_for_scope is also recursion stuff

View File

@@ -179,7 +179,9 @@ def test_dir(completion_test_dir, third_party=False):
if f_name.endswith(".py"): if f_name.endswith(".py"):
if third_party: if third_party:
try: 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: except ImportError:
summary.append('Thirdparty-Library %s not found.' % summary.append('Thirdparty-Library %s not found.' %
f_name) f_name)