use ImportPath.is_relative_import instead of complicated lookups all the time

This commit is contained in:
David Halter
2013-08-11 18:14:58 +04:30
parent 81e625862e
commit 1121588678
+4 -5
View File
@@ -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):