Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934) #106323

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,13 @@ def test_builtin_on_metaclasses(self):
# Testing that the subclasses section does not appear
self.assertNotIn('Built-in subclasses', text)

def test_fail_help_output_redirect(self):
with StringIO() as buf:
helper = pydoc.Helper(output=buf)
helper.help("abd")
expected = missing_pattern % "abd"
self.assertEqual(expected, buf.getvalue().strip().replace('\n', os.linesep))

@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
'trace function introduces __locals__ unexpectedly')
@requires_docstrings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make pydoc.doc catch bad module ImportError when output stream is not None.