gh-102541: Fix Helper.help("mod") for non-existent mod (#105934) · python/cpython@0530f4f · GitHub
Skip to content

Commit 0530f4f

Browse files
Eclips4terryjreedy
andauthored
gh-102541: Fix Helper.help("mod") for non-existent mod (#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. --------- Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 46d7761 commit 0530f4f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/pydoc.py

Lines changed: 5 additions & 1 deletion

Lib/test/test_pydoc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ def test_builtin_on_metaclasses(self):
631631
# Testing that the subclasses section does not appear
632632
self.assertNotIn('Built-in subclasses', text)
633633

634+
def test_fail_help_output_redirect(self):
635+
with StringIO() as buf:
636+
helper = pydoc.Helper(output=buf)
637+
helper.help("abd")
638+
expected = missing_pattern % "abd"
639+
self.assertEqual(expected, buf.getvalue().strip().replace('\n', os.linesep))
640+
634641
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
635642
'trace function introduces __locals__ unexpectedly')
636643
@requires_docstrings
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)