mirror of
https://github.com/davidhalter/jedi.git
synced 2026-09-07 00:16:55 +08:00
use ImportPath.is_relative_import instead of complicated lookups all the time
This commit is contained in:
+4
-5
@@ -111,7 +111,7 @@ class ImportPath(pr.Base):
|
|||||||
names = []
|
names = []
|
||||||
for scope in self.follow():
|
for scope in self.follow():
|
||||||
if scope is ImportPath.GlobalNamespace:
|
if scope is ImportPath.GlobalNamespace:
|
||||||
if self.import_stmt.relative_count == 0:
|
if self.is_relative_import() == 0:
|
||||||
names += self.get_module_names()
|
names += self.get_module_names()
|
||||||
|
|
||||||
if self.file_path is not None:
|
if self.file_path is not None:
|
||||||
@@ -120,7 +120,7 @@ class ImportPath(pr.Base):
|
|||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
names += self.get_module_names([path])
|
names += self.get_module_names([path])
|
||||||
|
|
||||||
if self.import_stmt.relative_count:
|
if self.is_relative_import():
|
||||||
rel_path = self.get_relative_path() + '/__init__.py'
|
rel_path = self.get_relative_path() + '/__init__.py'
|
||||||
with common.ignored(IOError):
|
with common.ignored(IOError):
|
||||||
m = modules.Module(rel_path)
|
m = modules.Module(rel_path)
|
||||||
@@ -247,7 +247,7 @@ class ImportPath(pr.Base):
|
|||||||
path = None
|
path = None
|
||||||
if ns_path:
|
if ns_path:
|
||||||
path = ns_path
|
path = ns_path
|
||||||
elif self.import_stmt.relative_count:
|
elif self.is_relative_import():
|
||||||
path = self.get_relative_path()
|
path = self.get_relative_path()
|
||||||
|
|
||||||
global imports_processed
|
global imports_processed
|
||||||
@@ -290,8 +290,7 @@ class ImportPath(pr.Base):
|
|||||||
try:
|
try:
|
||||||
current_namespace = follow_str(current_namespace[1], s)
|
current_namespace = follow_str(current_namespace[1], s)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if self.import_stmt.relative_count \
|
if self.is_relative_import() and len(self.import_path) == 1:
|
||||||
and len(self.import_path) == 1:
|
|
||||||
# follow `from . import some_variable`
|
# follow `from . import some_variable`
|
||||||
rel_path = self.get_relative_path()
|
rel_path = self.get_relative_path()
|
||||||
with common.ignored(ImportError):
|
with common.ignored(ImportError):
|
||||||
|
|||||||
Reference in New Issue
Block a user