Skip to content
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

Merged
merged 4 commits into from Jan 3, 2024

Conversation

fipachu
Copy link
Contributor

@fipachu fipachu commented Oct 17, 2023

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

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.
@bedevere-app
Copy link

bedevere-app bot commented Oct 17, 2023

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 skip news label instead.

@@ -0,0 +1,2 @@
:meth:`cmd.Cmd.do_help` now cleans docstrings with :func:`inspect.cleandoc`
Copy link
Contributor Author

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.

Copy link
Member

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.

@fipachu
Copy link
Contributor Author

fipachu commented Jan 2, 2024

I have since learned that I shouldn't reformat old code and add new code in the same commit. Sorry about that.

Copy link
Member

@gvanrossum gvanrossum left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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

@fipachu
Copy link
Contributor Author

fipachu commented Jan 3, 2024

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.)

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.

Copy link
Member

@gvanrossum gvanrossum left a 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`
Copy link
Member

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.

@gvanrossum gvanrossum enabled auto-merge (squash) January 3, 2024 19:30
@gvanrossum gvanrossum merged commit 4c4b08d into python:main Jan 3, 2024
31 checks passed
@fipachu fipachu deleted the fix-issue-52161 branch January 3, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance Cmd support for docstrings and document it.
3 participants