diff options
author | Ned Deily <nad@acm.org> | 2011-10-06 21:17:44 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2011-10-06 21:17:44 (GMT) |
commit | 0096fb5780170b36a9f2ec9f1e2a780887c2768d (patch) | |
tree | 32dfd417642e942013da13883a362a1e6f8d99b9 /Lib/pydoc.py | |
parent | ac6874c4bb3b7123e395d24d209658129aa63b40 (diff) | |
download | cpython-0096fb5780170b36a9f2ec9f1e2a780887c2768d.zip cpython-0096fb5780170b36a9f2ec9f1e2a780887c2768d.tar.gz cpython-0096fb5780170b36a9f2ec9f1e2a780887c2768d.tar.bz2 |
Issue #7425: Prevent pydoc -k failures due to module import errors.
(Backport to 2.7 of existing 3.x fix)
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index d08d1ac..d557790 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -52,7 +52,7 @@ Richard Chamberlain, for the first implementation of textdoc. # the current directory is changed with os.chdir(), an incorrect # path will be displayed. -import sys, imp, os, re, types, inspect, __builtin__, pkgutil +import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings from repr import Repr from string import expandtabs, find, join, lower, split, strip, rfind, rstrip from traceback import extract_tb @@ -1968,10 +1968,11 @@ def apropos(key): if modname[-9:] == '.__init__': modname = modname[:-9] + ' (package)' print modname, desc and '- ' + desc - try: import warnings - except ImportError: pass - else: warnings.filterwarnings('ignore') # ignore problems during import - ModuleScanner().run(callback, key) + def onerror(modname): + pass + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') # ignore problems during import + ModuleScanner().run(callback, key, onerror=onerror) # --------------------------------------------------- web browser interface |