From 515a74fbf9c5eb6a5dbc7cbbb5b3910eab966466 Mon Sep 17 00:00:00 2001
From: Alexandre Vassalotti <alexandre@peadrop.com>
Date: Sun, 5 Jul 2009 06:42:44 +0000
Subject: [PATCH] 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.
---
 Lib/pkgutil.py           | 3 +--
 Lib/test/test_pkgutil.py | 6 ++++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 27dd887d869..0ec6ec52654 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 169ef664113..f69af5a86bf 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]
-- 
2.30.9