From 8059b075c6cb6cf2edbb91ed8410c3ee18fcb7d4 Mon Sep 17 00:00:00 2001 From: David Halter Date: Wed, 10 Oct 2012 22:55:07 +0200 Subject: [PATCH] handled import statement recursions --- jedi/imports.py | 11 +++++++++-- test/completion/imports.py | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jedi/imports.py b/jedi/imports.py index a836bc44..7c9a31d9 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -132,6 +132,10 @@ class ImportPath(object): """ Returns the imported modules. """ + if evaluate.follow_statement.push_stmt(self.import_stmt): + # check recursion + return [] + if self.import_path: try: scope, rest = self._follow_file_system() @@ -159,6 +163,8 @@ class ImportPath(object): else: scopes = [ImportPath.GlobalNamespace] debug.dbg('after import', scopes) + + evaluate.follow_statement.pop_stmt() return scopes def _follow_file_system(self): @@ -243,7 +249,7 @@ def strip_imports(scopes): return result -def remove_star_imports(scope): +def remove_star_imports(scope, ignored_modules=[]): """ Check a module for star imports: >>> from module import * @@ -253,7 +259,8 @@ def remove_star_imports(scope): modules = strip_imports(i for i in scope.get_imports() if i.star) new = [] for m in modules: - new += remove_star_imports(m) + if m not in ignored_modules: + new += remove_star_imports(m, modules) modules += new # Filter duplicate modules. diff --git a/test/completion/imports.py b/test/completion/imports.py index 0d565e36..f8ab6f03 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -201,3 +201,7 @@ from .. import run #? [] from not_a_module import + +# self import +# this can cause recursions +from imports import *