mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 09:18:36 +08:00
Some simplifications
This commit is contained in:
@@ -258,27 +258,28 @@ class Importer(object):
|
|||||||
"""Returns the import path as pure strings instead of `Name`."""
|
"""Returns the import path as pure strings instead of `Name`."""
|
||||||
return tuple(
|
return tuple(
|
||||||
name.value if isinstance(name, tree.Name) else name
|
name.value if isinstance(name, tree.Name) else name
|
||||||
for name in self.import_path)
|
for name in self.import_path
|
||||||
|
)
|
||||||
|
|
||||||
def sys_path_with_modifications(self):
|
def sys_path_with_modifications(self):
|
||||||
in_path = []
|
|
||||||
sys_path_mod = self._evaluator.get_sys_path() \
|
sys_path_mod = self._evaluator.get_sys_path() \
|
||||||
+ sys_path.check_sys_path_modifications(self.module_context)
|
+ sys_path.check_sys_path_modifications(self.module_context)
|
||||||
if self.file_path is not None:
|
if self.file_path is not None:
|
||||||
# If you edit e.g. gunicorn, there will be imports like this:
|
# If you edit e.g. gunicorn, there will be imports like this:
|
||||||
# `from gunicorn import something`. But gunicorn is not in the
|
# `from gunicorn import something`. But gunicorn is not in the
|
||||||
# sys.path. Therefore look if gunicorn is a parent directory, #56.
|
# sys.path. Therefore look if gunicorn is a parent directory, #56.
|
||||||
if self.import_path: # TODO is this check really needed?
|
if self.import_path:
|
||||||
for path in sys_path.traverse_parents(self.file_path):
|
for path in sys_path.traverse_parents(self.file_path):
|
||||||
if os.path.basename(path) == self.str_import_path[0]:
|
if os.path.basename(path) == self.str_import_path[0]:
|
||||||
in_path.append(force_unicode(os.path.dirname(path)))
|
sys_path_mod.insert(0, force_unicode(os.path.dirname(path)))
|
||||||
|
break
|
||||||
|
|
||||||
# Since we know nothing about the call location of the sys.path,
|
# Since we know nothing about the call location of the sys.path,
|
||||||
# it's a possibility that the current directory is the origin of
|
# it's a possibility that the current directory is the origin of
|
||||||
# the Python execution.
|
# the Python execution.
|
||||||
sys_path_mod.append(force_unicode(os.path.dirname(self.file_path)))
|
sys_path_mod.append(force_unicode(os.path.dirname(self.file_path)))
|
||||||
|
|
||||||
return in_path + sys_path_mod
|
return sys_path_mod
|
||||||
|
|
||||||
def follow(self):
|
def follow(self):
|
||||||
if not self.import_path:
|
if not self.import_path:
|
||||||
|
|||||||
Reference in New Issue
Block a user