fix issues with os.path completions

This commit is contained in:
Dave Halter
2014-04-11 10:33:32 +02:00
parent 840a806246
commit a6bfb1b3ad
2 changed files with 7 additions and 3 deletions

View File

@@ -493,7 +493,7 @@ class Completion(BaseDefinition):
# separately in Completion. # separately in Completion.
if self._definition.isinstance(pr.Import) and self._definition.alias is None: if self._definition.isinstance(pr.Import) and self._definition.alias is None:
i = imports.ImportPath(self._evaluator, self._definition, True) i = imports.ImportPath(self._evaluator, self._definition, True)
import_path = tuple(i.import_path + [unicode(self._name)]) import_path = i.import_path + (unicode(self._name),)
return imports.get_importer(self._evaluator, import_path, return imports.get_importer(self._evaluator, import_path,
i._importer.module).follow(self._evaluator) i._importer.module).follow(self._evaluator)
return super(Completion, self)._follow_statements_imports() return super(Completion, self)._follow_statements_imports()

View File

@@ -107,7 +107,7 @@ class ImportPath(pr.Base):
if self.is_just_from: if self.is_just_from:
# In the case of an import like `from x.` we don't need to # In the case of an import like `from x.` we don't need to
# add all the variables. # add all the variables.
if ['os'] == self.import_path and not self._is_relative_import(): if ('os',) == self.import_path and not self._is_relative_import():
# os.path is a hardcoded exception, because it's a # os.path is a hardcoded exception, because it's a
# ``sys.modules`` modification. # ``sys.modules`` modification.
names.append(self._generate_name('path')) names.append(self._generate_name('path'))
@@ -195,7 +195,7 @@ class ImportPath(pr.Base):
# follow the rest of the import (not FS -> classes, functions) # follow the rest of the import (not FS -> classes, functions)
if len(rest) > 1 or rest and self.is_like_search: if len(rest) > 1 or rest and self.is_like_search:
scopes = [] scopes = []
if ['os', 'path'] == self.import_path[:2] \ if ('os', 'path') == self.import_path[:2] \
and not self._is_relative_import(): and not self._is_relative_import():
# This is a huge exception, we follow a nested import # This is a huge exception, we follow a nested import
# ``os.path``, because it's a very important one in Python # ``os.path``, because it's a very important one in Python
@@ -226,6 +226,10 @@ def get_importer(evaluator, import_path, module, level=0):
Checks the evaluator caches first, which resembles the ``sys.modules`` Checks the evaluator caches first, which resembles the ``sys.modules``
cache and speeds up libraries like ``numpy``. cache and speeds up libraries like ``numpy``.
""" """
if level != 0:
# Only absolute imports should be cached. Otherwise we have a mess.
# TODO Maybe calculate the absolute import and save it here?
return _Importer(evaluator, import_path, module, level)
try: try:
return evaluator.import_cache[import_path] return evaluator.import_cache[import_path]
except KeyError: except KeyError: