davidhalter/jedi — pull request #366 by blink1073 (2014-01-12 15:33:05+00:00)
Title: Fix import behavior for dotted compiled modules

Trying to use dotted modules broke the existing implementation. The error-producing code and traceback are below. This change allows dotted modules (in this case `numpy.core.umath`) to be found and used if they are in `sys.modules`, or imported if they are not.

```python
>>> import jedi
>>> code = 'import numpy'
>>> script = jedi.Script(code, 1, len(code))
>>> script.goto_definitions()
Traceback (most recent call last):
File "", line 1, in
File "/home/silvester/workspace/jedi/jedi/api/__init__.py", line 373, in goto_definitions
scopes = resolve_import_paths(scopes)
File "/home/silvester/workspace/jedi/jedi/api/__init__.py", line 338, in resolve_import_paths
scopes.update(resolve_import_paths(set(s.follow())))
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 201, in follow
scopes += remove_star_imports(self._evaluator, scope)
File "/home/silvester/workspace/jedi/jedi/cache.py", line 142, in wrapper
mods = func(evaluator, scope, *args, **kwargs)
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 391, in remove_star_imports
modules = strip_imports(evaluator, (i for i in scope.get_imports() if i.star))
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 376, in strip_imports
result += ImportPath(evaluator, s).follow()
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 201, in follow
scopes += remove_star_imports(self._evaluator, scope)
File "/home/silvester/workspace/jedi/jedi/cache.py", line 142, in wrapper
mods = func(evaluator, scope, *args, **kwargs)
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 391, in remove_star_imports
modules = strip_imports(evaluator, (i for i in scope.get_imports() if i.star))
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 376, in strip_imports
result += ImportPath(evaluator, s).follow()
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 201, in follow
scopes += remove_star_imports(self._evaluator, scope)
File "/home/silvester/workspace/jedi/jedi/cache.py", line 142, in wrapper
mods = func(evaluator, scope, *args, **kwargs)
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 391, in remove_star_imports
modules = strip_imports(evaluator, (i for i in scope.get_imports() if i.star))
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 376, in strip_imports
result += ImportPath(evaluator, s).follow()
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 194, in follow
scope, rest = self._follow_file_system()
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 291, in _follow_file_system
return self._follow_sys_path(sys_path_mod)
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 363, in _follow_sys_path
return load_module(path, source), rest
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 416, in load_module
return load(source) if cached is None else cached.module
File "/home/silvester/workspace/jedi/jedi/evaluate/imports.py", line 409, in load
return compiled.load_module(path, name)
File "/home/silvester/workspace/jedi/jedi/evaluate/compiled.py", line 130, in load_module
exec_function('import %s as module' % name, content)
File "blub", line 2, in exec_function
File "", line 1, in
ImportError: No module named umath
```