https://github.com/python/cpython/commit/99d965635ae2ac4bffdc318ee05b96c59262d165 commit: 99d965635ae2ac4bffdc318ee05b96c59262d165 branch: main author: donBarbos <donbar...@proton.me> committer: gpshead <g...@krypto.org> date: 2025-02-17T20:06:08Z summary:
gh-118761: Improve import time of `cmd` module (#130056) * Improve import time of `cmd` module * Remove string import files: A Misc/NEWS.d/next/Library/2025-02-13-02-03-38.gh-issue-118761.le_qEg.rst M Lib/cmd.py diff --git a/Lib/cmd.py b/Lib/cmd.py index c333e099bd8c9a..438b88aa1049cc 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -42,12 +42,15 @@ 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 @@ 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..4a5b7f6b5de6cd --- /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. _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com