mirror of
https://github.com/python/cpython
synced 2024-10-14 12:14:35 +00:00
gh-52161: Enhance Cmd support for docstrings (#110987)
In `cmd.Cmd.do_help` call `inspect.cleandoc()`, to clean indentation and remove leading/trailing empty lines from a dosctring before printing.
This commit is contained in:
parent
f1f8392432
commit
4c4b08dd2b
|
@ -42,7 +42,7 @@
|
||||||
functions respectively.
|
functions respectively.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import string, sys
|
import inspect, string, sys
|
||||||
|
|
||||||
__all__ = ["Cmd"]
|
__all__ = ["Cmd"]
|
||||||
|
|
||||||
|
@ -305,6 +305,7 @@ def do_help(self, arg):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
doc=getattr(self, 'do_' + arg).__doc__
|
doc=getattr(self, 'do_' + arg).__doc__
|
||||||
|
doc = inspect.cleandoc(doc)
|
||||||
if doc:
|
if doc:
|
||||||
self.stdout.write("%s\n"%str(doc))
|
self.stdout.write("%s\n"%str(doc))
|
||||||
return
|
return
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc`
|
||||||
|
before writing them. Patch by Filip Łapkiewicz.
|
Loading…
Reference in a new issue