mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
fix issues with os.path completions
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user