Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve import time of :mod:`cmd` by lazy importing :mod:`inspect` and
removing :mod:`string`. Patch by Semyon Moroz.
Loading