gh-118761: Improve import time of cmd module (#130056)

* Improve import time of `cmd` module
* Remove string import
This commit is contained in:
donBarbos 2025-02-18 00:06:08 +04:00 committed by GitHub
parent 6f07016bf0
commit 99d965635a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View 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

View file

@ -0,0 +1,2 @@
Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and
removing :mod:`string`. Patch by Semyon Moroz.