From a4d5b80b09319b377838ea85d0aeeabb6a3a88e8 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 19 Oct 2022 23:48:00 +0900 Subject: [PATCH 1/2] gh-98374: Suppress ImportError for invalid query for help() command. --- Lib/pydoc.py | 6 +++++- .../2022-10-19-23-48-46.gh-issue-98374.eOBh8M.rst | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-10-19-23-48-46.gh-issue-98374.eOBh8M.rst diff --git a/Lib/pydoc.py b/Lib/pydoc.py index a4dc910c8a8e89..b4a876ee9c29e1 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1997,7 +1997,11 @@ def __repr__(self): _GoInteractive = object() def __call__(self, request=_GoInteractive): if request is not self._GoInteractive: - self.help(request) + try: + self.help(request) + except ImportError as e: + self.output.write(str(e)) + self.output.write("\n") else: self.intro() self.interact() diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-10-19-23-48-46.gh-issue-98374.eOBh8M.rst b/Misc/NEWS.d/next/Core and Builtins/2022-10-19-23-48-46.gh-issue-98374.eOBh8M.rst new file mode 100644 index 00000000000000..56a41e3883d111 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-10-19-23-48-46.gh-issue-98374.eOBh8M.rst @@ -0,0 +1,2 @@ +Suppress ImportError for invalid query for help() command. Patch by Dong-hee +Na. From f9619bad3ca9d8bd1795ad1b0a3ffefb07c8bd8b Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 20 Oct 2022 08:03:54 +0900 Subject: [PATCH 2/2] Address code review --- Lib/pydoc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b4a876ee9c29e1..c79ec77a8c09e4 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -2000,8 +2000,7 @@ def __call__(self, request=_GoInteractive): try: self.help(request) except ImportError as e: - self.output.write(str(e)) - self.output.write("\n") + self.output.write(f'{e}\n') else: self.intro() self.interact()