]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 21 Jan 2022 19:32:43 +0000 (11:32 -0800)
committerGitHub <noreply@github.com>
Fri, 21 Jan 2022 19:32:43 +0000 (11:32 -0800)
(cherry picked from commit 60705cff70576482fea31dcafbf8a37cbb751ea5)

Co-authored-by: Tom Sparrow <793763+sparrowt@users.noreply.github.com>
Lib/pdb.py
Lib/test/test_pdb.py
Misc/ACKS
Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst [new file with mode: 0644]

index 943211158ac41e417496bdccbbcfb8a113504ae0..7ab50b4845d3e6ffae5b73133c0e1ef255affb69 100755 (executable)
@@ -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
index d4c037dabff97e0cf9780b35e3cfc62a169048e9..6ac1a4a3c302551020ac3ed375542fc18cc4ab86 100644 (file)
@@ -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
index 9292bdc8dc73b737d39056f6775106a63a74ed0e..7f9166cd74cfabd983e3a28f018976414f00e72c 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1668,6 +1668,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 (file)
index 0000000..6000781
--- /dev/null
@@ -0,0 +1,2 @@
+:mod:`pdb` now gracefully handles ``help`` when :attr:`__doc__` is missing,
+for example when run with pregenerated optimized ``.pyc`` files.