gh-52161: Enhance Cmd support for docstrings#110987
Conversation
do_help will now clean indentation and remove leading/trailing empty lines from a dosctring before printing. Also minor PEP 8 compliance fixes in lines close to my additions.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| @@ -0,0 +1,2 @@ | |||
| :meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc` | |||
There was a problem hiding this comment.
I don't know if ":meth:cmd.Cmd.do_help" is correct, there definitely is no cmd.Cmd.do_help anchor in the documentation. Maybe I'd need to update the documentation to give do_help a separate section. I'm open to feedback here and in general.
There was a problem hiding this comment.
It seems to work. Let's not worry about it.
|
I have since learned that I shouldn't reformat old code and add new code in the same commit. Sorry about that. |
gvanrossum
left a comment
There was a problem hiding this comment.
Hi @fipachu, thanks for your contribution. It looks like you ran the code through some kind of auto-formatter. Can you please undo that? It gets in the way of finding the actual changes you are making, and blurs the git history. (In general we don't accept code cleanup changes, and we definitely don't want them mixed up with semantic changes.)
| try: | ||
| doc=getattr(self, 'do_' + arg).__doc__ | ||
| doc = getattr(self, 'do_' + arg).__doc__ | ||
| doc = inspect.cleandoc(doc) |
There was a problem hiding this comment.
IIUIC, this line is the actual patch
There was a problem hiding this comment.
Yeah, this and, obviously, the additional import
Sure! I thought I'm allowed to do reformatting, just not in the same commit as my change. I'll be back in a minute. |
gvanrossum
left a comment
There was a problem hiding this comment.
Thanks, this makes sense. I'll merge once tests pass.
| @@ -0,0 +1,2 @@ | |||
| :meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc` | |||
There was a problem hiding this comment.
It seems to work. Let's not worry about it.
In `cmd.Cmd.do_help` call `inspect.cleandoc()`, to clean indentation and remove leading/trailing empty lines from a dosctring before printing.
In `cmd.Cmd.do_help` call `inspect.cleandoc()`, to clean indentation and remove leading/trailing empty lines from a dosctring before printing.
In `cmd.Cmd.do_help` call `inspect.cleandoc()`, to clean indentation and remove leading/trailing empty lines from a dosctring before printing.
do_help will now clean indentation and remove leading/trailing empty lines from a dosctring before printing using inspect.cleandoc()
Also minor PEP 8 compliance fixes in lines close to my additions.The issue also calls for documenting suport for docstrings, but that's already done as far as I can see.
Fixes: #52161