From 81e625862e35dffcc77a03b1cef4802dae919f74 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 11 Aug 2013 18:10:21 +0430 Subject: [PATCH] os.path is now accessible, but nested imports in general are not. fixes #213, #230 --- jedi/imports.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jedi/imports.py b/jedi/imports.py index e8bf2659..4c3de666 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -202,6 +202,13 @@ class ImportPath(pr.Base): # follow the rest of the import (not FS -> classes, functions) if len(rest) > 1 or rest and self.is_like_search: scopes = [] + if ['os', 'path'] == self.import_path[:2] \ + and not self.is_relative_import(): + # This is a huge exception, we follow a nested import + # ``os.path``, because it's a very important one in Python + # that is being achieved by messing with ``sys.modules`` in + # ``os``. + scopes = evaluate.follow_path(iter(rest), scope, scope) elif rest: if is_goto: scopes = itertools.chain.from_iterable( @@ -222,6 +229,9 @@ class ImportPath(pr.Base): evaluate.follow_statement.pop_stmt() return scopes + def is_relative_import(self): + return bool(self.import_stmt.relative_count) + def get_relative_path(self): path = self.file_path for i in range(self.import_stmt.relative_count - 1):