Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed27df7

Browse files
committed
Issue #7367: Fix pkgutil.walk_paths to skip directories whose
contents cannot be read.
1 parent caf5a22 commit ed27df7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/pkgutil.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,11 @@ def iter_modules(self, prefix=''):
191191

192192
yielded = {}
193193
import inspect
194-
195-
filenames = os.listdir(self.path)
194+
try:
195+
filenames = os.listdir(self.path)
196+
except OSError:
197+
# ignore unreadable directories like import does
198+
filenames = []
196199
filenames.sort() # handle packages before same-named modules
197200

198201
for fn in filenames:
@@ -205,7 +208,12 @@ def iter_modules(self, prefix=''):
205208

206209
if not modname and os.path.isdir(path) and '.' not in fn:
207210
modname = fn
208-
for fn in os.listdir(path):
211+
try:
212+
dircontents = os.listdir(path)
213+
except OSError:
214+
# ignore unreadable directories like import does
215+
dircontents = []
216+
for fn in dircontents:
209217
subname = inspect.getmodulename(fn)
210218
if subname=='__init__':
211219
ispkg = True

0 commit comments

Comments
 (0)