diff options
author | Gregory Anders <github@gpanders.com> | 2021-08-26 06:22:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 14:22:02 +0200 |
commit | 8868d48712aee2b490efaf60bed8dfe9fb14d6b7 (patch) | |
tree | 91eb1d83da1952490da5ec89bc6432c0e6cabe34 /Lib/pydoc.py | |
parent | 21fa8547921d28b80b8a88d034081cab000d5480 (diff) | |
download | cpython-git-8868d48712aee2b490efaf60bed8dfe9fb14d6b7.tar.gz |
bpo-44967: pydoc: return non-zero exit code when query is not found (GH-27868)
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 9f0acd0271..b2915bfdfc 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1775,24 +1775,18 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0, def doc(thing, title='Python Library Documentation: %s', forceload=0, output=None): """Display text documentation, given an object or a path to an object.""" - try: - if output is None: - pager(render_doc(thing, title, forceload)) - else: - output.write(render_doc(thing, title, forceload, plaintext)) - except (ImportError, ErrorDuringImport) as value: - print(value) + if output is None: + pager(render_doc(thing, title, forceload)) + else: + output.write(render_doc(thing, title, forceload, plaintext)) def writedoc(thing, forceload=0): """Write HTML documentation to a file in the current directory.""" - try: - object, name = resolve(thing, forceload) - page = html.page(describe(object), html.document(object, name)) - with open(name + '.html', 'w', encoding='utf-8') as file: - file.write(page) - print('wrote', name + '.html') - except (ImportError, ErrorDuringImport) as value: - print(value) + object, name = resolve(thing, forceload) + page = html.page(describe(object), html.document(object, name)) + with open(name + '.html', 'w', encoding='utf-8') as file: + file.write(page) + print('wrote', name + '.html') def writedocs(dir, pkgpath='', done=None): """Write out HTML documentation for all modules in a directory tree.""" @@ -2786,7 +2780,7 @@ def cli(): for arg in args: if ispath(arg) and not os.path.exists(arg): print('file %r does not exist' % arg) - break + sys.exit(1) try: if ispath(arg) and os.path.isfile(arg): arg = importfile(arg) @@ -2797,8 +2791,9 @@ def cli(): writedoc(arg) else: help.help(arg) - except ErrorDuringImport as value: + except (ImportError, ErrorDuringImport) as value: print(value) + sys.exit(1) except (getopt.error, BadUsage): cmd = os.path.splitext(os.path.basename(sys.argv[0]))[0] |