mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
follow imports if they are in the file path, fixes davidhalter/jedi-vim#56
This commit is contained in:
@@ -146,8 +146,18 @@ class ImportPath(parsing.Base):
|
|||||||
return names
|
return names
|
||||||
|
|
||||||
def sys_path_with_modifications(self):
|
def sys_path_with_modifications(self):
|
||||||
|
# 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.
|
||||||
|
parts = self.file_path.split(os.path.sep)
|
||||||
|
in_path = []
|
||||||
|
for i, p in enumerate(parts):
|
||||||
|
if p == self.import_path[0]:
|
||||||
|
new = os.path.sep.join(parts[:i])
|
||||||
|
in_path.append(new)
|
||||||
|
|
||||||
module = self.import_stmt.get_parent_until()
|
module = self.import_stmt.get_parent_until()
|
||||||
return modules.sys_path_with_modifications(module)
|
return in_path + modules.sys_path_with_modifications(module)
|
||||||
|
|
||||||
def follow(self, is_goto=False):
|
def follow(self, is_goto=False):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
a = 1
|
a = 1
|
||||||
|
from import_tree.random import a as c
|
||||||
|
|||||||
@@ -215,3 +215,11 @@ from not_a_module import
|
|||||||
# self import
|
# self import
|
||||||
# this can cause recursions
|
# this can cause recursions
|
||||||
from imports import *
|
from imports import *
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# packages
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
from import_tree.mod1 import c
|
||||||
|
#? set
|
||||||
|
c
|
||||||
|
|||||||
Reference in New Issue
Block a user