diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-01 23:15:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-01 23:15:44 (GMT) |
commit | 9e335860188229a7985fe9a8b72ee62c684aa9eb (patch) | |
tree | 7584de0c1372d8da2a798431dff1d405bd218401 /Lib/pydoc.py | |
parent | f5e29f424597a970d7cfde3402891259e0e4c1dd (diff) | |
download | cpython-9e335860188229a7985fe9a8b72ee62c684aa9eb.zip cpython-9e335860188229a7985fe9a8b72ee62c684aa9eb.tar.gz cpython-9e335860188229a7985fe9a8b72ee62c684aa9eb.tar.bz2 |
[3.11] gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934) (#106323)
gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934)
If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------
(cherry picked from commit 0530f4f64629ff97f3feb7524da0833b9535e8b6)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 151c7e8..5e191bc 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1788,7 +1788,11 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0, raise print(exc) else: - output.write(render_doc(thing, title, forceload, plaintext)) + try: + s = render_doc(thing, title, forceload, plaintext) + except ImportError as exc: + s = str(exc) + output.write(s) def writedoc(thing, forceload=0): """Write HTML documentation to a file in the current directory.""" |