summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-01-21 19:32:43 (GMT)
committerGitHub <noreply@github.com>2022-01-21 19:32:43 (GMT)
commit05063fa15c594012e6dc9c2c7a3ea72e7cb933f2 (patch)
treeb64351e6fd67cbb7f0c1e349dd4d96e55a51b854 /Lib
parenta1015c6478e8cbec2ecb984a3cba733783d168b5 (diff)
downloadcpython-05063fa15c594012e6dc9c2c7a3ea72e7cb933f2.zip
cpython-05063fa15c594012e6dc9c2c7a3ea72e7cb933f2.tar.gz
cpython-05063fa15c594012e6dc9c2c7a3ea72e7cb933f2.tar.bz2
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
(cherry picked from commit 60705cff70576482fea31dcafbf8a37cbb751ea5) Co-authored-by: Tom Sparrow <793763+sparrowt@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/pdb.py3
-rw-r--r--Lib/test/test_pdb.py21
2 files changed, 24 insertions, 0 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 9432111..7ab50b4 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1493,6 +1493,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index d4c037d..6ac1a4a 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1463,6 +1463,27 @@ def bœr():
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