forked from VimPlug/jedi
handled import statement recursions
This commit is contained in:
@@ -132,6 +132,10 @@ class ImportPath(object):
|
|||||||
"""
|
"""
|
||||||
Returns the imported modules.
|
Returns the imported modules.
|
||||||
"""
|
"""
|
||||||
|
if evaluate.follow_statement.push_stmt(self.import_stmt):
|
||||||
|
# check recursion
|
||||||
|
return []
|
||||||
|
|
||||||
if self.import_path:
|
if self.import_path:
|
||||||
try:
|
try:
|
||||||
scope, rest = self._follow_file_system()
|
scope, rest = self._follow_file_system()
|
||||||
@@ -159,6 +163,8 @@ class ImportPath(object):
|
|||||||
else:
|
else:
|
||||||
scopes = [ImportPath.GlobalNamespace]
|
scopes = [ImportPath.GlobalNamespace]
|
||||||
debug.dbg('after import', scopes)
|
debug.dbg('after import', scopes)
|
||||||
|
|
||||||
|
evaluate.follow_statement.pop_stmt()
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
def _follow_file_system(self):
|
def _follow_file_system(self):
|
||||||
@@ -243,7 +249,7 @@ def strip_imports(scopes):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def remove_star_imports(scope):
|
def remove_star_imports(scope, ignored_modules=[]):
|
||||||
"""
|
"""
|
||||||
Check a module for star imports:
|
Check a module for star imports:
|
||||||
>>> from module import *
|
>>> 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)
|
modules = strip_imports(i for i in scope.get_imports() if i.star)
|
||||||
new = []
|
new = []
|
||||||
for m in modules:
|
for m in modules:
|
||||||
new += remove_star_imports(m)
|
if m not in ignored_modules:
|
||||||
|
new += remove_star_imports(m, modules)
|
||||||
modules += new
|
modules += new
|
||||||
|
|
||||||
# Filter duplicate modules.
|
# Filter duplicate modules.
|
||||||
|
|||||||
@@ -201,3 +201,7 @@ from .. import run
|
|||||||
|
|
||||||
#? []
|
#? []
|
||||||
from not_a_module import
|
from not_a_module import
|
||||||
|
|
||||||
|
# self import
|
||||||
|
# this can cause recursions
|
||||||
|
from imports import *
|
||||||
|
|||||||
Reference in New Issue
Block a user