File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 4343
4444 SUFFIXES = importlib .machinery .all_suffixes ()
4545else :
46+ import imp
47+
4648 SUFFIXES = [suffix for suffix , mode , type in imp .get_suffixes ()]
4749
4850# The cached list of all known modules
@@ -158,20 +160,23 @@ def find_modules(path):
158160 # Workaround for issue #166
159161 continue
160162 try :
163+ is_package = False
161164 with warnings .catch_warnings ():
162165 warnings .simplefilter ("ignore" , ImportWarning )
163166 fo , pathname , _ = imp .find_module (name , [path ])
167+ if fo is not None :
168+ fo .close ()
169+ else :
170+ # Yay, package
171+ is_package = True
164172 except (ImportError , IOError , SyntaxError ):
165173 continue
166174 except UnicodeEncodeError :
167175 # Happens with Python 3 when there is a filename in some
168176 # invalid encoding
169177 continue
170178 else :
171- if fo is not None :
172- fo .close ()
173- else :
174- # Yay, package
179+ if is_package :
175180 for subname in find_modules (pathname ):
176181 if subname != "__init__" :
177182 yield "%s.%s" % (name , subname )
You can’t perform that action at this time.
0 commit comments