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

Skip to content

Commit 515a74f

Browse files
committed
Issue 4005: Remove .sort() call on dict_keys object.
This caused pydoc to fail when there was a zip file in sys.path. Patch contributed by Amaury Forgeot d'Arc.
1 parent 2fef5b4 commit 515a74f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/pkgutil.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def get_filename(self, fullname=None):
318318
from zipimport import zipimporter
319319

320320
def iter_zipimport_modules(importer, prefix=''):
321-
dirlist = zipimport._zip_directory_cache[importer.archive].keys()
322-
dirlist.sort()
321+
dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
323322
_prefix = importer.prefix
324323
plen = len(_prefix)
325324
yielded = {}

Lib/test/test_pkgutil.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def test_getdata_zipfile(self):
7474
self.assertEqual(res1, RESOURCE_DATA)
7575
res2 = pkgutil.get_data(pkg, 'sub/res.txt')
7676
self.assertEqual(res2, RESOURCE_DATA)
77+
78+
names = []
79+
for loader, name, ispkg in pkgutil.iter_modules([zip_file]):
80+
names.append(name)
81+
self.assertEqual(names, ['test_getdata_zipfile'])
82+
7783
del sys.path[0]
7884

7985
del sys.modules[pkg]

0 commit comments

Comments
 (0)