Skip to content

gh-138094: Fix misleading suggestions in interactive help prompt - #138095

Open
adqm wants to merge 7 commits into
python:mainfrom
adqm:pydoc_interactive_suggestions
Open

adqm wants to merge 7 commits into
python:mainfrom
adqm:pydoc_interactive_suggestions

Conversation

@adqm

@adqm adqm commented Aug 23, 2025 •

Copy link
Copy Markdown
Contributor

This PR represents an attempt to address both of the issues raised in #138094 by changing how help(help) is handled, and by removing suggested calls to help(...) in the output when we can't find a given topic in interactive mode.

Happy to adjust if need be (or to separate this into 2 PR's if that would be better).

@ZeroIntensity ZeroIntensity 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.

I think it's worth adding an entry to the "What's New in Python 3.15" page too, because this seems like a feature, not a bugfix.

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-08-23-14-07-56.gh-issue-138094.U92SHS.rst Outdated
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@adqm

adqm commented Aug 24, 2025

Copy link
Copy Markdown
Contributor Author

I think it's worth adding an entry to the "What's New in Python 3.15" page

I'm not sure, just because this PR alone represents pretty minor tweaks to help's behavior. But maybe in conjunction with #137966 if these both get merged in, it would make sense? I also have a few other ideas in mind so there may be additional help-related PR's coming when I have a chance.

Of course, happy to defer to y'all's judgment, though.

@ZeroIntensity

Copy link
Copy Markdown
Member

Alternatively, we could add a .. versionchanged note to help, because this is a behavior change. #137966 should definitely get a whatsnew entry, though.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 28, 2026

def test_fail_help_cli(self):
elines = (missing_pattern % 'abd').splitlines()
elines = (missing_pattern % 'abd').splitlines(False)[:1]

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.

Positional boolean arguments are a code smell because they're often unreadable. Could you change this (and other occurrences) to splitlines(keepends=False)?

Comment thread Lib/pydoc.py
Comment on lines +2108 to +2109
elif isinstance(request, (Helper, type(builtins.help))):
self.helphelp(is_interactive=is_interactive)

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.

When Python is started without site initialization (-S), builtins.help isn't available, so this will raise an exception when pydoc.help is invoked manually. Let's use _sitebuiltins._Helper instead.

Comment thread Lib/pydoc.py
if is_interactive:
self.intro()
else:
pager(textwrap.dedent("""\

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.

Calls to pager() need to be guarded by a self.output is None check, because we don't want to start the pager when output is being redirected. So, we want something like this instead:

help_text = textwrap.dedent(...)
if is_interactive:
    self.intro()
elif self._output is None:
    pager(help_text)
else:
    self.output.write(help_text)

@@ -0,0 +1,2 @@
Removed potentially-misleading suggestions from the interactive :func:`help`

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.

I think the dash is unnecessary here? Correct me if I'm wrong on this one.

Suggested change
Removed potentially-misleading suggestions from the interactive :func:`help`
Removed potentially misleading suggestions from the interactive :func:`help`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants