Skip to content

gh-52161: Enhance Cmd support for docstrings#110987

Merged
gvanrossum merged 4 commits into
python:mainfrom
fipachu:fix-issue-52161
Jan 3, 2024
Merged

gh-52161: Enhance Cmd support for docstrings#110987
gvanrossum merged 4 commits into
python:mainfrom
fipachu:fix-issue-52161

Conversation

@fipachu

@fipachu fipachu commented Oct 17, 2023

Copy link
Copy Markdown
Contributor

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

bedevere-app Bot commented Oct 17, 2023

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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

fipachu commented Jan 2, 2024

Copy link
Copy Markdown
Contributor Author

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

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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

Comment thread Lib/cmd.py
try:
doc=getattr(self, 'do_' + arg).__doc__
doc = getattr(self, 'do_' + arg).__doc__
doc = inspect.cleandoc(doc)

Copy link
Copy Markdown
Member

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
Copy Markdown
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

fipachu commented Jan 3, 2024

Copy link
Copy Markdown
Contributor Author

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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@fipachu
fipachu deleted the fix-issue-52161 branch January 3, 2024 19:53
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
In `cmd.Cmd.do_help` call `inspect.cleandoc()`,
to clean indentation and remove leading/trailing empty
lines from a dosctring before printing.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
In `cmd.Cmd.do_help` call `inspect.cleandoc()`,
to clean indentation and remove leading/trailing empty
lines from a dosctring before printing.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
In `cmd.Cmd.do_help` call `inspect.cleandoc()`,
to clean indentation and remove leading/trailing empty
lines from a dosctring before printing.
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