]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-52161: Enhance Cmd support for docstrings (#110987)
authorFilip Łapkiewicz <80906036+fipachu@users.noreply.github.com>
Wed, 3 Jan 2024 19:37:34 +0000 (20:37 +0100)
committerGitHub <noreply@github.com>
Wed, 3 Jan 2024 19:37:34 +0000 (19:37 +0000)
In `cmd.Cmd.do_help` call `inspect.cleandoc()`,
to clean indentation and remove leading/trailing empty
lines from a dosctring before printing.

Lib/cmd.py
Misc/NEWS.d/next/Library/2023-10-17-16-11-03.gh-issue-52161.WBYyCJ.rst [new file with mode: 0644]

index 2e358d6cd5a02de775c1cbe58e2f6f7d6a6cdfe1..a37d16cd7bde163dda325cd1a90ce6dda1144b4e 100644 (file)
@@ -42,7 +42,7 @@ listings of documented functions, miscellaneous topics, and undocumented
 functions respectively.
 """
 
-import string, sys
+import inspect, string, sys
 
 __all__ = ["Cmd"]
 
@@ -305,6 +305,7 @@ class Cmd:
             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 (file)
index 0000000..3f598d4
--- /dev/null
@@ -0,0 +1,2 @@
+:meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc`\r
+before writing them. Patch by Filip Łapkiewicz.