]> granicus.if.org Git - python/commitdiff
Issue 3145: help("modules xxx") failed when scanning test.badsyntax_pep3120...
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 19 Jun 2008 20:54:32 +0000 (20:54 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 19 Jun 2008 20:54:32 +0000 (20:54 +0000)
now it silently ignores modules it cannot scan or import.

Lib/pydoc.py
Misc/NEWS

index 8e80b37e7cb5969953dcaa718cab18de0363664e..2c559bd26e927f0afc5bd935317253fd7c7adca0 100755 (executable)
@@ -1870,16 +1870,25 @@ class ModuleScanner:
             else:
                 loader = importer.find_module(modname)
                 if hasattr(loader,'get_source'):
+                    try:
+                        source = loader.get_source(modname)
+                    except UnicodeDecodeError:
+                        if onerror:
+                            onerror(modname)
+                        continue
                     import io
-                    desc = source_synopsis(
-                        io.StringIO(loader.get_source(modname))
-                    ) or ''
+                    desc = source_synopsis(io.StringIO(source)) or ''
                     if hasattr(loader,'get_filename'):
                         path = loader.get_filename(modname)
                     else:
                         path = None
                 else:
-                    module = loader.load_module(modname)
+                    try:
+                        module = loader.load_module(modname)
+                    except ImportError:
+                        if onerror:
+                            onerror(modname)
+                        continue
                     desc = (module.__doc__ or '').splitlines()[0]
                     path = getattr(module,'__file__',None)
                 name = modname + ' - ' + desc
@@ -1895,10 +1904,12 @@ def apropos(key):
         if modname[-9:] == '.__init__':
             modname = modname[:-9] + ' (package)'
         print(modname, desc and '- ' + desc)
+    def onerror(modname):
+        pass
     try: import warnings
     except ImportError: pass
     else: warnings.filterwarnings('ignore') # ignore problems during import
-    ModuleScanner().run(callback, key)
+    ModuleScanner().run(callback, key, onerror=onerror)
 
 # --------------------------------------------------- web browser interface
 
index 0d5379b69870dc2aa948f84b1c3438cfcf42593e..0656041f8a21ff8570c0c011e8665114f82c1749 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,6 +4,21 @@ Python News
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's new in Python 3.0b2?
+===========================
+
+*Release date: XX-XXX-2008*
+
+Core and Builtins
+-----------------
+
+Library
+-------
+
+- Issue #3145: help("modules whatever") failed when trying to load the source
+  code of every single module of the standard library, including invalid files
+  used in the test suite.
+
 What's new in Python 3.0b1?
 ===========================