forked from VimPlug/jedi
Fixed relative imports.
This commit is contained in:
@@ -57,7 +57,8 @@ class ImportWrapper():
|
|||||||
try:
|
try:
|
||||||
module = self._import.get_parent_until()
|
module = self._import.get_parent_until()
|
||||||
import_path = self._import.path_for_name(self._name)
|
import_path = self._import.path_for_name(self._name)
|
||||||
importer = get_importer(self._evaluator, tuple(import_path), module, level=0)
|
importer = get_importer(self._evaluator, tuple(import_path),
|
||||||
|
module, self._import.level)
|
||||||
try:
|
try:
|
||||||
module, rest = importer.follow_file_system()
|
module, rest = importer.follow_file_system()
|
||||||
except ModuleNotFound as e:
|
except ModuleNotFound as e:
|
||||||
|
|||||||
@@ -1088,12 +1088,6 @@ class Import(Simple):
|
|||||||
return path[:path.index(name) + 1]
|
return path[:path.index(name) + 1]
|
||||||
raise ValueError('Name should be defined in the import itself')
|
raise ValueError('Name should be defined in the import itself')
|
||||||
|
|
||||||
@property
|
|
||||||
def level(self):
|
|
||||||
"""The level parameter of ``__import__``."""
|
|
||||||
# TODO implement
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def is_nested(self):
|
def is_nested(self):
|
||||||
"""
|
"""
|
||||||
This checks for the special case of nested imports, without aliases and
|
This checks for the special case of nested imports, without aliases and
|
||||||
@@ -1119,6 +1113,17 @@ class ImportFrom(Import):
|
|||||||
return dict((alias, name) for name, alias in self._as_name_tuples()
|
return dict((alias, name) for name, alias in self._as_name_tuples()
|
||||||
if alias is not None)
|
if alias is not None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def level(self):
|
||||||
|
"""The level parameter of ``__import__``."""
|
||||||
|
level = 0
|
||||||
|
for n in self.children[1:]:
|
||||||
|
if n in ('.', '...'):
|
||||||
|
level += len(n.value)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return level
|
||||||
|
|
||||||
def _as_name_tuples(self):
|
def _as_name_tuples(self):
|
||||||
last = self.children[-1]
|
last = self.children[-1]
|
||||||
if last == ')':
|
if last == ')':
|
||||||
@@ -1137,9 +1142,9 @@ class ImportFrom(Import):
|
|||||||
yield as_name.children[::2] # yields x, y -> ``x as y``
|
yield as_name.children[::2] # yields x, y -> ``x as y``
|
||||||
|
|
||||||
def _paths(self):
|
def _paths(self):
|
||||||
n = self.children[1]
|
for n in self.children[1:]:
|
||||||
if self.children[1] in ('.', '...'):
|
if n not in ('.', '...'):
|
||||||
raise NotImplementedError
|
break
|
||||||
if is_node(n, 'dotted_name'):
|
if is_node(n, 'dotted_name'):
|
||||||
dotted = n.children[::2]
|
dotted = n.children[::2]
|
||||||
else:
|
else:
|
||||||
@@ -1152,6 +1157,11 @@ class ImportName(Import):
|
|||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
return [alias or path[0] for path, alias in self._dotted_as_names()]
|
return [alias or path[0] for path, alias in self._dotted_as_names()]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def level(self):
|
||||||
|
"""The level parameter of ``__import__``."""
|
||||||
|
return 0 # Obviously 0 for imports without from.
|
||||||
|
|
||||||
def _paths(self):
|
def _paths(self):
|
||||||
return [path for path, alias in self._dotted_as_names()]
|
return [path for path, alias in self._dotted_as_names()]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user