From: donBarbos Date: Mon, 17 Feb 2025 20:06:08 +0000 (+0400) Subject: gh-118761: Improve import time of `cmd` module (#130056) X-Git-Tag: v3.14.0a6~379 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99d965635ae2ac4bffdc318ee05b96c59262d165;p=thirdparty%2FPython%2Fcpython.git gh-118761: Improve import time of `cmd` module (#130056) * Improve import time of `cmd` module * Remove string import --- diff --git a/Lib/cmd.py b/Lib/cmd.py index c333e099bd8c..438b88aa1049 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -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 index 000000000000..4a5b7f6b5de6 --- /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` and +removing :mod:`string`. Patch by Semyon Moroz.