From edf1b9799c2b26d55283c02217a427da18eeeb4e Mon Sep 17 00:00:00 2001 From: donBarbos Date: Thu, 13 Feb 2025 02:01:46 +0400 Subject: [PATCH 1/3] Improve import time of `cmd` module --- Lib/cmd.py | 6 ++++-- .../Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst diff --git a/Lib/cmd.py b/Lib/cmd.py index c333e099bd8c9a..eb40697efeb07b 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -42,7 +42,7 @@ functions respectively. """ -import inspect, string, sys +import string, sys __all__ = ["Cmd"] @@ -303,9 +303,11 @@ def do_help(self, arg): try: func = getattr(self, 'help_' + arg) except AttributeError: + from inspect import cleandoc + try: doc=getattr(self, 'do_' + arg).__doc__ - doc = inspect.cleandoc(doc) + doc = cleandoc(doc) if doc: self.stdout.write("%s\n"%str(doc)) return diff --git a/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst b/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst new file mode 100644 index 00000000000000..f12d77e2f70072 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst @@ -0,0 +1,2 @@ +Improve import time of :mod:`cmd` by lazy importing :mod:`inspect`. Patch by +Semyon Moroz. From 527fdb078b548308bee27d0bdb4a189d354579f0 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Mon, 17 Feb 2025 23:36:52 +0400 Subject: [PATCH 2/3] Remove string import --- Lib/cmd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/cmd.py b/Lib/cmd.py index eb40697efeb07b..438b88aa1049cc 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -42,12 +42,15 @@ functions respectively. """ -import string, sys +import sys __all__ = ["Cmd"] PROMPT = '(Cmd) ' -IDENTCHARS = string.ascii_letters + string.digits + '_' +IDENTCHARS = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789' + '_') class Cmd: """A simple framework for writing line-oriented command interpreters. From ae16858083f9f8b36fd5519be24c269b826e273a Mon Sep 17 00:00:00 2001 From: donBarbos Date: Mon, 17 Feb 2025 23:41:46 +0400 Subject: [PATCH 3/3] Update Next.d entry --- .../Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst b/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst index f12d77e2f70072..4a5b7f6b5de6cd 100644 --- a/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst +++ b/Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst @@ -1,2 +1,2 @@ -Improve import time of :mod:`cmd` by lazy importing :mod:`inspect`. Patch by -Semyon Moroz. +Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and +removing :mod:`string`. Patch by Semyon Moroz.