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-102541: Fix Helper.help("mod") for non-existent mod #105934

Merged
merged 8 commits into from
Jul 1, 2023

Conversation

Eclips4
Copy link
Member

@Eclips4 Eclips4 commented Jun 20, 2023

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in `pydoc.doc. The same error is caught when output is None.

import pydoc
from io import StringIO

input = StringIO()
output = StringIO()
help = pydoc.Helper(input, output)
help.help("abd")
input.close()
output.close()

Traceback:

./python example.py
Running debug|x64 interpreter...
Traceback (most recent call last):
  File "C:\Users\KIRILL-1\CLionProjects\cpython\example.py", line 7, in <module>
    help.help("abd", is_cli=True)
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 2067, in help
    elif request: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1793, in doc
    output.write(render_doc(thing, title, forceload, plaintext))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1760, in render_doc
    object, name = resolve(thing, forceload)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1746, in resolve
    raise ImportError('''\
ImportError: No Python documentation found for 'abd'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

EDITED by terryjreedy July 1, 2023 to better describe the issue, so I could review the patch,
and show the current result after the merge of the first PR for the issue. Instead of the last line
there were about 15 lines that repeated the Traceback.

@Eclips4
Copy link
Member Author

Eclips4 commented Jun 20, 2023

cc @corona10

@corona10
Copy link
Member

corona10 commented Jun 20, 2023

@terryjreedy @Yhg1s @ambv

I am out of OSS for this month. If this PR is urgent, I would like to request reviewing of this PR to other reviewers.

Lib/test/test_pydoc.py Outdated Show resolved Hide resolved
@corona10 corona10 requested review from ambv, Yhg1s and terryjreedy June 20, 2023 13:04
@terryjreedy terryjreedy changed the title gh-102541: Fix Helper.help when output is non default gh-102541: Fix Helper.help("mod") for non-existent mod Jul 1, 2023
Lib/pydoc.py Outdated Show resolved Hide resolved
@terryjreedy terryjreedy added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Jul 1, 2023
@terryjreedy terryjreedy merged commit 0530f4f into python:main Jul 1, 2023
@miss-islington
Copy link
Contributor

Thanks @Eclips4 for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2023
…H-105934)

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------

(cherry picked from commit 0530f4f)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
@bedevere-bot
Copy link

GH-106322 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Jul 1, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2023
…H-105934)

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------

(cherry picked from commit 0530f4f)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
@bedevere-bot
Copy link

GH-106323 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 1, 2023
terryjreedy added a commit that referenced this pull request Jul 1, 2023
) (#106323)

gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934)

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------

(cherry picked from commit 0530f4f)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
terryjreedy added a commit that referenced this pull request Jul 1, 2023
) (#106322)

gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934)

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------

(cherry picked from commit 0530f4f)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
@Eclips4 Eclips4 deleted the issue-102541 branch July 2, 2023 20:25
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.

6 participants