New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)
| @@ -297,13 +300,14 @@ def do_help(self, arg): | |||
| func = getattr(self, 'help_' + arg) | |||
| except AttributeError: | |||
| try: | |||
| doc=getattr(self, 'do_' + arg).__doc__ | |||
| doc = getattr(self, 'do_' + arg).__doc__ | |||
| doc = inspect.cleandoc(doc) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUIC, this line is the actual patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work. Let's not worry about it.
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