From 8dea9ab60885d1877944c9ca9335e7c592b9db92 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:37:59 +0000 Subject: [PATCH 1/5] bpo-46434: TDD for missing docstring in pdb help --- Lib/test/test_pdb.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 01263db28f18cd..b2ecc02b53a236 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1474,6 +1474,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 From 39616c1b785d6243000671d73e0de8d383981f27 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:38:15 +0000 Subject: [PATCH 2/5] bpo-46434: Improve handling of missing docstring in pdb help --- Lib/pdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/pdb.py b/Lib/pdb.py index d7110074538ace..58bc720275a280 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1577,6 +1577,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 From ebe9c4c459e739855c62d497245499e168e8370e Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 20 Jan 2022 10:35:52 +0000 Subject: [PATCH 3/5] bpo-46434: update NEWS and ACKS --- Misc/ACKS | 1 + .../next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst diff --git a/Misc/ACKS b/Misc/ACKS index 04d6a651489bbb..cf023c9af927ab 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1675,6 +1675,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 00000000000000..8e16b6fd8a193a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst @@ -0,0 +1,2 @@ +pdb help now gracefully handles any case where __doc__ is missing, for +example when run from a windows embeddable package From 676b9fa6a6cf8525d343dc48503b59600ff2e417 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 20 Jan 2022 10:36:24 +0000 Subject: [PATCH 4/5] bpo-46434: consistent indentation --- Lib/test/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index b2ecc02b53a236..d2bf3dc90ed239 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1491,7 +1491,7 @@ def do_testcmdwithnodocs(self, arg): 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') + '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') From ba2053d34cad7b4c3efb46d7312c135c999523d6 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 20 Jan 2022 15:06:47 +0000 Subject: [PATCH 5/5] bpo-46434: improved NEWS entry Co-authored-by: Steve Dower --- .../next/Library/2022-01-20-10-35-10.bpo-46434.geS-aP.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 8e16b6fd8a193a..6000781fa5aea9 100644 --- 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 @@ -1,2 +1,2 @@ -pdb help now gracefully handles any case where __doc__ is missing, for -example when run from a windows embeddable package +:mod:`pdb` now gracefully handles ``help`` when :attr:`__doc__` is missing, +for example when run with pregenerated optimized ``.pyc`` files.