From: Alexandre Vassalotti Date: Sun, 5 Jul 2009 06:42:44 +0000 (+0000) Subject: Issue 4005: Remove .sort() call on dict_keys object. X-Git-Tag: v3.2a1~2877 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=515a74fbf9c5eb6a5dbc7cbbb5b3910eab966466;p=python 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. --- diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index 27dd887d86..0ec6ec5265 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -318,8 +318,7 @@ try: from zipimport import zipimporter def iter_zipimport_modules(importer, prefix=''): - dirlist = zipimport._zip_directory_cache[importer.archive].keys() - dirlist.sort() + dirlist = sorted(zipimport._zip_directory_cache[importer.archive]) _prefix = importer.prefix plen = len(_prefix) yielded = {} diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index 169ef66411..f69af5a86b 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -74,6 +74,12 @@ class PkgutilTests(unittest.TestCase): self.assertEqual(res1, RESOURCE_DATA) res2 = pkgutil.get_data(pkg, 'sub/res.txt') self.assertEqual(res2, RESOURCE_DATA) + + names = [] + for loader, name, ispkg in pkgutil.iter_modules([zip_file]): + names.append(name) + self.assertEqual(names, ['test_getdata_zipfile']) + del sys.path[0] del sys.modules[pkg]