[Python-checkins] bpo-46434: Handle missing docstrings in pdb help (GH-30705)

miss-islington webhook-mailer at python.org
Fri Jan 21 12:33:29 EST 2022


https://github.com/python/cpython/commit/c3ad850b57f92bd7c5515616b59afbd9e1c79538
commit: c3ad850b57f92bd7c5515616b59afbd9e1c79538
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-01-21T09:33:25-08:00
summary:

bpo-46434: Handle missing docstrings in pdb help (GH-30705)

(cherry picked from commit 60705cff70576482fea31dcafbf8a37cbb751ea5)

Co-authored-by: Tom Sparrow <793763+sparrowt at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst
M Lib/pdb.py
M Lib/test/test_pdb.py
M Misc/ACKS

diff --git a/Lib/pdb.py b/Lib/pdb.py
index 943211158ac41..7ab50b4845d3e 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -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
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index cb9cd07b07143..58778300eee09 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -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
diff --git a/Misc/ACKS b/Misc/ACKS
index 25c88656d4245..61267d2a23bea 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1640,6 +1640,7 @@ Evgeny Sologubov
 Cody Somerville
 Anthony Sottile
 Edoardo Spadolini
+Tom Sparrow
 Geoffrey Spear
 Clay Spence
 Stefan Sperling
diff --git a/Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst b/Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst
new file mode 100644
index 0000000000000..6000781fa5aea
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst
@@ -0,0 +1,2 @@
+:mod:`pdb` now gracefully handles ``help`` when :attr:`__doc__` is missing,
+for example when run with pregenerated optimized ``.pyc`` files.



More information about the Python-checkins mailing list