Skip to content

Commit 60705cf

Browse files
authored
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
1 parent a1bf329 commit 60705cf

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
@@ -1577,6 +1577,9 @@ def do_help(self, arg):
15771577
self.error('No help for %r; please do not run Python with -OO '
15781578
'if you need command help' % arg)
15791579
return
1580+
if command.__doc__ is None:
1581+
self.error('No help for %r; __doc__ string missing' % arg)
1582+
return
15801583
self.message(command.__doc__.rstrip())
15811584

15821585
do_h = do_help

Lib/test/test_pdb.py

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

1477+
def test_issue46434(self):
1478+
# Temporarily patch in an extra help command which doesn't have a
1479+
# docstring to emulate what happens in an embeddable distribution
1480+
script = """
1481+
def do_testcmdwithnodocs(self, arg):
1482+
pass
1483+
1484+
import pdb
1485+
pdb.Pdb.do_testcmdwithnodocs = do_testcmdwithnodocs
1486+
"""
1487+
commands = """
1488+
continue
1489+
help testcmdwithnodocs
1490+
"""
1491+
stdout, stderr = self.run_pdb_script(script, commands)
1492+
output = (stdout or '') + (stderr or '')
1493+
self.assertNotIn('AttributeError', output,
1494+
'Calling help on a command with no docs should be handled gracefully')
1495+
self.assertIn("*** No help for 'testcmdwithnodocs'; __doc__ string missing", output,
1496+
'Calling help on a command with no docs should print an error')
1497+
14771498
def test_issue13183(self):
14781499
script = """
14791500
from bar import bar

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,7 @@ Evgeny Sologubov
16751675
Cody Somerville
16761676
Anthony Sottile
16771677
Edoardo Spadolini
1678+
Tom Sparrow
16781679
Geoffrey Spear
16791680
Clay Spence
16801681
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)