mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-118761: Improve import time of cmd
module (#130056)
* Improve import time of `cmd` module * Remove string import
This commit is contained in:
parent
6f07016bf0
commit
99d965635a
2 changed files with 10 additions and 3 deletions
11
Lib/cmd.py
11
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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and
|
||||
removing :mod:`string`. Patch by Semyon Moroz.
|
Loading…
Add table
Add a link
Reference in a new issue