From 30cfdee32521aafedb98fd1737991d6a32085169 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 16 Feb 2018 10:21:43 +0100 Subject: [PATCH] Some simplifications --- jedi/evaluate/imports.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index d0a4a97f..637f284a 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -258,27 +258,28 @@ class Importer(object): """Returns the import path as pure strings instead of `Name`.""" return tuple( 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): - in_path = [] sys_path_mod = self._evaluator.get_sys_path() \ + sys_path.check_sys_path_modifications(self.module_context) if self.file_path is not None: # If you edit e.g. gunicorn, there will be imports like this: # `from gunicorn import something`. But gunicorn is not in the # 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): 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, # it's a possibility that the current directory is the origin of # the Python execution. 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): if not self.import_path: