mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
follow 'from . import variable', fixes parts of davidhalter/jedi-vim#56
This commit is contained in:
@@ -187,16 +187,20 @@ class ImportPath(parsing.Base):
|
||||
"""
|
||||
Find a module with a path (of the module, like usb.backend.libusb10).
|
||||
"""
|
||||
def follow_str(ns, string):
|
||||
debug.dbg('follow_module', ns, string)
|
||||
path = None
|
||||
if ns:
|
||||
path = ns[1]
|
||||
elif self.import_stmt.relative_count:
|
||||
def get_relative_path():
|
||||
module = self.import_stmt.get_parent_until()
|
||||
path = os.path.abspath(module.path)
|
||||
for i in range(self.import_stmt.relative_count):
|
||||
path = os.path.dirname(path)
|
||||
return path
|
||||
|
||||
def follow_str(ns_path, string):
|
||||
debug.dbg('follow_module', ns_path, string)
|
||||
path = None
|
||||
if ns_path:
|
||||
path = ns_path
|
||||
elif self.import_stmt.relative_count:
|
||||
path = get_relative_path()
|
||||
|
||||
global imports_processed
|
||||
imports_processed += 1
|
||||
@@ -221,14 +225,22 @@ class ImportPath(parsing.Base):
|
||||
else:
|
||||
sys_path_mod = list(builtin.get_sys_path())
|
||||
|
||||
current_namespace = None
|
||||
current_namespace = (None, None, None)
|
||||
# now execute those paths
|
||||
rest = []
|
||||
for i, s in enumerate(self.import_path):
|
||||
try:
|
||||
current_namespace = follow_str(current_namespace, s)
|
||||
current_namespace = follow_str(current_namespace[1], s)
|
||||
except ImportError:
|
||||
if current_namespace:
|
||||
if self.import_stmt.relative_count \
|
||||
and len(self.import_path) == 1:
|
||||
# follow `from . import some_variable`
|
||||
try:
|
||||
current_namespace = follow_str(get_relative_path(),
|
||||
'__init__')
|
||||
except ImportError:
|
||||
pass
|
||||
if current_namespace[1]:
|
||||
rest = self.import_path[i:]
|
||||
else:
|
||||
raise ModuleNotFound(
|
||||
|
||||
3
test/completion/__init__.py
Normal file
3
test/completion/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
""" needed for some modules to test against packages. """
|
||||
|
||||
some_variable = 1
|
||||
@@ -118,6 +118,9 @@ from import_tree.pkg.mod1 import a
|
||||
#! ['import os']
|
||||
from .imports import os
|
||||
|
||||
#! ['some_variable=1']
|
||||
from . import some_variable
|
||||
|
||||
# -----------------
|
||||
# anonymous classes
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user