Skip to content

Commit

Permalink
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
Browse files Browse the repository at this point in the history
(cherry picked from commit 60705cf)

Co-authored-by: Tom Sparrow <793763+sparrowt@users.noreply.github.com>
  • Loading branch information
miss-islington and sparrowt committed Jan 21, 2022
1 parent 656971e commit c3ad850
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/pdb.py
Expand Up @@ -1493,6 +1493,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
Expand Up @@ -1400,6 +1400,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
Expand Up @@ -1640,6 +1640,7 @@ Evgeny Sologubov
Cody Somerville
Anthony Sottile
Edoardo Spadolini
Tom Sparrow
Geoffrey Spear
Clay Spence
Stefan Sperling
Expand Down
@@ -0,0 +1,2 @@
:mod:`pdb` now gracefully handles ``help`` when :attr:`__doc__` is missing,
for example when run with pregenerated optimized ``.pyc`` files.

0 comments on commit c3ad850

Please sign in to comment.