https://github.com/python/cpython/commit/4c4b08dd2bd5f2cad4e41bf29119a3daa2956f6e
commit: 4c4b08dd2bd5f2cad4e41bf29119a3daa2956f6e
branch: main
author: Filip Łapkiewicz <[email protected]>
committer: gvanrossum <[email protected]>
date: 2024-01-03T19:37:34Z
summary:

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.

files:
A Misc/NEWS.d/next/Library/2023-10-17-16-11-03.gh-issue-52161.WBYyCJ.rst
M Lib/cmd.py

diff --git a/Lib/cmd.py b/Lib/cmd.py
index 2e358d6cd5a02d..a37d16cd7bde16 100644
--- a/Lib/cmd.py
+++ b/Lib/cmd.py
@@ -42,7 +42,7 @@
 functions respectively.
 """
 
-import string, sys
+import inspect, string, sys
 
 __all__ = ["Cmd"]
 
@@ -305,6 +305,7 @@ def do_help(self, arg):
             except AttributeError:
                 try:
                     doc=getattr(self, 'do_' + arg).__doc__
+                    doc = inspect.cleandoc(doc)
                     if doc:
                         self.stdout.write("%s\n"%str(doc))
                         return
diff --git 
a/Misc/NEWS.d/next/Library/2023-10-17-16-11-03.gh-issue-52161.WBYyCJ.rst 
b/Misc/NEWS.d/next/Library/2023-10-17-16-11-03.gh-issue-52161.WBYyCJ.rst
new file mode 100644
index 00000000000000..3f598d40e4ae93
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-10-17-16-11-03.gh-issue-52161.WBYyCJ.rst
@@ -0,0 +1,2 @@
+:meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc`
+before writing them. Patch by Filip Łapkiewicz.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to