summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-06-19 20:54:32 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-06-19 20:54:32 (GMT)
commit9196dc66ae57a7cb751a42d49e5ab6038c916ff7 (patch)
tree55fceff4c687701a6b69b565fed5efd13b26913c /Lib/pydoc.py
parentad4afeb02112e0b6ec41a879feb1946ad0ef2b64 (diff)
downloadcpython-9196dc66ae57a7cb751a42d49e5ab6038c916ff7.zip
cpython-9196dc66ae57a7cb751a42d49e5ab6038c916ff7.tar.gz
cpython-9196dc66ae57a7cb751a42d49e5ab6038c916ff7.tar.bz2
Issue 3145: help("modules xxx") failed when scanning test.badsyntax_pep3120...
now it silently ignores modules it cannot scan or import.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 8e80b37..2c559bd 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -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