]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118761: Improve import time of `cmd` module (#130056)
authordonBarbos <donbarbos@proton.me>
Mon, 17 Feb 2025 20:06:08 +0000 (00:06 +0400)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2025 20:06:08 +0000 (20:06 +0000)
* Improve import time of `cmd` module
* Remove string import

Lib/cmd.py
Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst [new file with mode: 0644]

index c333e099bd8c9a3da407793f0a86585640d38b97..438b88aa1049cca6e60a4e03ad3579f222665754 100644 (file)
@@ -42,12 +42,15 @@ listings of documented functions, miscellaneous topics, and undocumented
 functions respectively.
 """
 
-import inspect, 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.
@@ -303,9 +306,11 @@ class Cmd:
             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 (file)
index 0000000..4a5b7f6
--- /dev/null
@@ -0,0 +1,2 @@
+Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and
+removing :mod:`string`. Patch by Semyon Moroz.