Skip to content

Commit c3ad850

Browse files
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
(cherry picked from commit 60705cf) Co-authored-by: Tom Sparrow <[email protected]>
1 parent 656971e commit c3ad850

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

Lib/pdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,9 @@ def do_help(self, arg):
14931493
self.error('No help for %r; please do not run Python with -OO '
14941494
'if you need command help' % arg)
14951495
return
1496+
if command.__doc__ is None:
1497+
self.error('No help for %r; __doc__ string missing' % arg)
1498+
return
14961499
self.message(command.__doc__.rstrip())
14971500

14981501
do_h = do_help

Lib/test/test_pdb.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,27 @@ def test_issue7964(self):
14001400
self.assertNotIn(b'SyntaxError', stdout,
14011401
"Got a syntax error running test script under PDB")
14021402

1403+
def test_issue46434(self):
1404+
# Temporarily patch in an extra help command which doesn't have a
1405+
# docstring to emulate what happens in an embeddable distribution
1406+
script = """
1407+
def do_testcmdwithnodocs(self, arg):
1408+
pass
1409+
1410+
import pdb
1411+
pdb.Pdb.do_testcmdwithnodocs = do_testcmdwithnodocs
1412+
"""
1413+
commands = """
1414+
continue
1415+
help testcmdwithnodocs
1416+
"""
1417+
stdout, stderr = self.run_pdb_script(script, commands)
1418+
output = (stdout or '') + (stderr or '')
1419+
self.assertNotIn('AttributeError', output,
1420+
'Calling help on a command with no docs should be handled gracefully')
1421+
self.assertIn("*** No help for 'testcmdwithnodocs'; __doc__ string missing", output,
1422+
'Calling help on a command with no docs should print an error')
1423+
14031424
def test_issue13183(self):
14041425
script = """
14051426
from bar import bar

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,7 @@ Evgeny Sologubov
16401640
Cody Somerville
16411641
Anthony Sottile
16421642
Edoardo Spadolini
1643+
Tom Sparrow
16431644
Geoffrey Spear
16441645
Clay Spence
16451646
Stefan Sperling
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`pdb` now gracefully handles ``help`` when :attr:`__doc__` is missing,
2+
for example when run with pregenerated optimized ``.pyc`` files.

0 commit comments

Comments
 (0)