Skip to content

help CLI shows a traceback when import failed #102541

Description

@Eclips4

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.11only security fixes
    3.12only security fixes
    and removed
    type-featureA feature request or enhancement
    on Mar 8, 2023
  2. terryjreedy commented on Mar 8, 2023

    @terryjreedy
    Member

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

  3. Eclips4 commented on Mar 8, 2023

    @Eclips4
    MemberAuthor

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

  4. Eclips4 commented on Mar 9, 2023

    @Eclips4
    MemberAuthor

    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)

  5. added a commit that references this issue on Mar 11, 2023
  6. Eclips4 commented on Jun 12, 2023

    @Eclips4
    MemberAuthor

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

  7. terryjreedy commented on Jun 12, 2023

    @terryjreedy
    Member

    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.

  8. Eclips4 commented on Jun 12, 2023

    @Eclips4
    MemberAuthor

    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

  9. added
    3.13only security fixes
    and removed on Jun 12, 2023
  10. 21 remaining items

  11. added 2 commits that reference this issue on Jul 1, 2023
  12. terryjreedy commented on Jul 2, 2023

    @terryjreedy
    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?

  13. added a commit that references this issue on Jul 2, 2023
  14. Yhg1s commented on Jul 11, 2023

    @Yhg1s
    Member

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

  15. Eclips4 commented on Jul 11, 2023

    @Eclips4
    MemberAuthor

    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.

  16. terryjreedy commented on Jul 11, 2023

    @terryjreedy
    Member

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

  17. added a commit that references this issue on Jul 11, 2023
  18. added 2 commits that reference this issue on Jul 11, 2023
  19. Eclips4 commented on Jul 11, 2023

    @Eclips4
    MemberAuthor

    Thank you very much @terryjreedy for your help!

  20. added 2 commits that reference this issue on Jul 11, 2023
  21. Eclips4 commented on Jul 11, 2023

    @Eclips4
    MemberAuthor

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions