Skip to content

Commit cccdbda

Browse files
fipachuaisk
authored andcommitted
pythongh-52161: Enhance Cmd support for docstrings (python#110987)
In `cmd.Cmd.do_help` call `inspect.cleandoc()`, to clean indentation and remove leading/trailing empty lines from a dosctring before printing.
1 parent 8b8f285 commit cccdbda

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/cmd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
functions respectively.
4343
"""
4444

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

4747
__all__ = ["Cmd"]
4848

@@ -305,6 +305,7 @@ def do_help(self, arg):
305305
except AttributeError:
306306
try:
307307
doc=getattr(self, 'do_' + arg).__doc__
308+
doc = inspect.cleandoc(doc)
308309
if doc:
309310
self.stdout.write("%s\n"%str(doc))
310311
return
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc`
2+
before writing them. Patch by Filip Łapkiewicz.

0 commit comments

Comments
 (0)