Skip to content

bpo-46434: Handle missing docstring in pdb help #30705

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

Merged
merged 5 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,9 @@ def do_help(self, arg):
self.error('No help for %r; please do not run Python with -OO '
'if you need command help' % arg)
return
if command.__doc__ is None:
self.error('No help for %r; __doc__ string missing' % arg)
return
self.message(command.__doc__.rstrip())

do_h = do_help
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,27 @@ def test_issue7964(self):
self.assertNotIn(b'SyntaxError', stdout,
"Got a syntax error running test script under PDB")

def test_issue46434(self):
# Temporarily patch in an extra help command which doesn't have a
# docstring to emulate what happens in an embeddable distribution
script = """
def do_testcmdwithnodocs(self, arg):
pass

import pdb
pdb.Pdb.do_testcmdwithnodocs = do_testcmdwithnodocs
"""
commands = """
continue
help testcmdwithnodocs
"""
stdout, stderr = self.run_pdb_script(script, commands)
output = (stdout or '') + (stderr or '')
self.assertNotIn('AttributeError', output,
'Calling help on a command with no docs should be handled gracefully')
self.assertIn("*** No help for 'testcmdwithnodocs'; __doc__ string missing", output,
'Calling help on a command with no docs should print an error')

def test_issue13183(self):
script = """
from bar import bar
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ Evgeny Sologubov
Cody Somerville
Anthony Sottile
Edoardo Spadolini
Tom Sparrow
Geoffrey Spear
Clay Spence
Stefan Sperling
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pdb help now gracefully handles any case where __doc__ is missing, for
example when run from a windows embeddable package
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pdb help now gracefully handles any case where __doc__ is missing, for
example when run from a windows embeddable package
:mod:`pdb` now gracefully handles any case where :attr:`__doc__` is missing, for
example when run with pregenerated optimized ``.pyc`` files.

FYI, I found the special references by searching the Doc folder for other examples. These will turn them into links in the final doc.

Copy link
Contributor Author

@sparrowt sparrowt Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool thank you, good to know! Maybe it's not important but should we retain a reference to help in there given it's the help command within pdb which has been fixed? Otherwise "any case" without the scope of 'help' feels like a bit of an overstatement (!)

Copy link
Contributor Author

@sparrowt sparrowt Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully ba2053d is ok