Skip to content

Commit 99d9656

Browse files
authored
gh-118761: Improve import time of cmd module (#130056)
* Improve import time of `cmd` module * Remove string import
1 parent 6f07016 commit 99d9656

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Lib/cmd.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@
4242
functions respectively.
4343
"""
4444

45-
import inspect, string, sys
45+
import sys
4646

4747
__all__ = ["Cmd"]
4848

4949
PROMPT = '(Cmd) '
50-
IDENTCHARS = string.ascii_letters + string.digits + '_'
50+
IDENTCHARS = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
51+
'abcdefghijklmnopqrstuvwxyz'
52+
'0123456789'
53+
'_')
5154

5255
class Cmd:
5356
"""A simple framework for writing line-oriented command interpreters.
@@ -303,9 +306,11 @@ def do_help(self, arg):
303306
try:
304307
func = getattr(self, 'help_' + arg)
305308
except AttributeError:
309+
from inspect import cleandoc
310+
306311
try:
307312
doc=getattr(self, 'do_' + arg).__doc__
308-
doc = inspect.cleandoc(doc)
313+
doc = cleandoc(doc)
309314
if doc:
310315
self.stdout.write("%s\n"%str(doc))
311316
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and
2+
removing :mod:`string`. Patch by Semyon Moroz.

0 commit comments

Comments
 (0)