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

help CLI shows a traceback when import failed #102541

Closed
Eclips4 opened this issue Mar 8, 2023 · 16 comments
Closed

help CLI shows a traceback when import failed #102541

Eclips4 opened this issue Mar 8, 2023 · 16 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes release-blocker type-bug An unexpected behavior, bug, or error

Comments

@Eclips4
Copy link
Member

Eclips4 commented Mar 8, 2023

Currently, help will show a traceback when we type name of something which doesn't exist:

help> 123
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen _sitebuiltins>", line 103, in __call__
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 2004, in __call__
    self.interact()
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 2031, in interact
    self.help(request)
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 2057, in help
    elif request: doc(request, 'Help on %s:', output=self._output)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1781, in doc
    pager(render_doc(thing, title, forceload))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1755, in render_doc
    object, name = resolve(thing, forceload)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\pydoc.py", line 1741, in resolve
    raise ImportError('''\
ImportError: No Python documentation found for '123'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.
>>>

I think, this shouldn't be shown.
Is there any reason for this?
Can we show something like
No python documentation found for '123'.?

Reproducible on current main.

Linked PRs

@Eclips4 Eclips4 added the type-feature A feature request or enhancement label Mar 8, 2023
@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error 3.11 only security fixes 3.12 bugs and security fixes 3.10 only security fixes and removed type-feature A feature request or enhancement labels Mar 8, 2023
@terryjreedy
Copy link
Member

terryjreedy commented Mar 8, 2023

I verified above in 3.11.2 and 3.12.0a6. 3.10.10 is better -- Gives import error message without traceback. But even better would be to give error message without ImportError and return to help> prompt. This should possibly be a separate PR as there might be more discussion that change. (It is possible that 3.11 change is intentional -- this should be checked.)

@Eclips4
Copy link
Member Author

Eclips4 commented Mar 8, 2023

How I understand, it's introduced in #89130.

@Eclips4
Copy link
Member Author

Eclips4 commented Mar 9, 2023

Yeah, i found right way to fix it. I I have slightly changed signature of some functions, which now have argument is_cli (set default to False).
That's doesn't break compatibility with issue which i mentioned above.
Currenly, in help prompt errors looks like that:

help> abd
No Python documentation found for 'abd'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

help>

@terryjreedy What you think about this?
BTW, all tests are passed.
I think, error message we should change, any ideas? (this will make us to change some lines in test_pydoc, but it's not hard)

@Eclips4
Copy link
Member Author

Eclips4 commented Jun 12, 2023

@terryjreedy
I think there's no need to backport it to 3.10 branch. I cannot reproduce it there

@terryjreedy
Copy link
Member

terryjreedy commented Jun 12, 2023

In closed duplicate #105702, I noted that there was no bug in latest release of 3.8, 3.9, or 3.10. Patch should restore previous behavior, shown on that issue, which is same as shown above. I just installed 32-bit 3.11.0 and it does have the bug. Will look at PR.

@Eclips4
Copy link
Member Author

Eclips4 commented Jun 12, 2023

In closed duplicate #105702, I noted that there was no bug in latest release of 3.8, 3.9, or 3.10. Patch should restore previous behavior, shown on that issue, which is same as shown above. I just installed 32-bit 3.11.0 and it does have the bug. Will look at PR.

Yeah, so, please, delete label 3.10 on this issue, and add 3.13 label, this still reproducible on current main

@terryjreedy
Copy link
Member

@ambv Kirill believes this regression resulted from your #27868. Whichever PR is the cause, CI passed because help() interaction is not adequately tested. Can help Kirill add one to the fix? (AFAIK, not trivial.)

This also caused a regression in IDLE, which may or may not be independently fixable. #105689 It would be really nice to fix this before the next releases.

Eclips4 added a commit to Eclips4/cpython that referenced this issue Jun 14, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 14, 2023
(cherry picked from commit ba516e7)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
@corona10
Copy link
Member

CI passed because help() interaction is not adequately tested.

Yeah, we have to add the test for interaction.

corona10 pushed a commit that referenced this issue Jun 15, 2023
gh-102541: Hide traceback in help prompt (gh-102614)
(cherry picked from commit ba516e7)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
@corona10 corona10 moved this from Todo to Done in Release and Deferred blockers 🚫 Jun 16, 2023
@corona10 corona10 added the type-bug An unexpected behavior, bug, or error label Jun 17, 2023
@Yhg1s
Copy link
Member

Yhg1s commented Jun 19, 2023

Is the only thing left to do here improving test coverage?

@Eclips4
Copy link
Member Author

Eclips4 commented Jun 20, 2023

Is the only thing left to do here improving test coverage?

Sadly, but no. When I tried to write a test for this case, I founded another bug. I have already sent PR to fix.

terryjreedy added a commit that referenced this issue Jul 1, 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.
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue 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 <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue 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 <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
terryjreedy added a commit that referenced this issue 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 <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
terryjreedy added a commit that referenced this issue 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 <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@terryjreedy
Copy link
Member

This issue is at least a near duplicate of issue #98374 and PR #98450, about help('invalid'), closed and merged.

@Eclips4 The 2nd fix is now merged and backported. Can you now write a test for the first one?

@Yhg1s
Copy link
Member

Yhg1s commented Jul 11, 2023

Okay, so now it's just about adding the last test case, right? 😅

@Eclips4
Copy link
Member Author

Eclips4 commented Jul 11, 2023

Okay, so now it's just about adding the last test case, right? 😅

Yeah, you're right.
I already sent a PR to add this, and waiting for review.

@terryjreedy
Copy link
Member

I reviewed and edited and intend to merge and close this after CI passes.

terryjreedy added a commit that referenced this issue Jul 11, 2023
Test fix for when one enters, for instance, 'abd' at the 'help>' prompt.
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 11, 2023
…thonGH-106340)

Test fix for when one enters, for instance, 'abd' at the 'help>' prompt.
---------

(cherry picked from commit 292ac4b)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 11, 2023
…thonGH-106340)

Test fix for when one enters, for instance, 'abd' at the 'help>' prompt.
---------

(cherry picked from commit 292ac4b)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@Eclips4
Copy link
Member Author

Eclips4 commented Jul 11, 2023

Thank you very much @terryjreedy for your help!

terryjreedy added a commit that referenced this issue Jul 11, 2023
…H-106340) (#106640)

gh-102541: Add test case for help() for non_existent_module (GH-106340)

Test fix for when one enters, for instance, 'abd' at the 'help>' prompt.
---------

(cherry picked from commit 292ac4b)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
terryjreedy added a commit that referenced this issue Jul 11, 2023
…H-106340) (#106639)

gh-102541: Add test case for help() for non_existent_module (GH-106340)

Test fix for when one enters, for instance, 'abd' at the 'help>' prompt.
---------

(cherry picked from commit 292ac4b)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@Eclips4
Copy link
Member Author

Eclips4 commented Jul 11, 2023

Now, all PR's merged and backported.
Everything that needed to be done was done.
Again, thanks Terry for his thorough help.

@Eclips4 Eclips4 closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes release-blocker type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

4 participants