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

ENH: Improve help() to suggest related commands when invalid input is given #127284

Open
bushraqurban opened this issue Nov 26, 2024 · 2 comments
Labels
pending The issue will be closed if no feedback is provided type-feature A feature request or enhancement

Comments

@bushraqurban
Copy link

bushraqurban commented Nov 26, 2024

Feature or enhancement

Proposal:

Problem

Currently, when a user enters an invalid input into help() (e.g., a misspelled function name or a non-existent function), the response is simply:

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

This doesn't help users who may have made a typo or are unsure of the correct function name. It would be more user-friendly if help() could suggest similar, valid commands from the available documentation in both the built-in Python modules and any currently imported modules.

Proposed Feature

When a user enters an invalid function or method name, help() should return a suggestion of closely related commands from the built-in and imported modules. For example, if the user types a misspelled method name, help() should suggest the correct method(s) from the current environment.

Example Usage

Input

help('pandas.duplicated()')

Output
Did you mean: help('pandas.DataFrame.duplicated')

Input

help('math.sqrted')

Output
Did you mean: help('math.sqrt')?

Benefits

  • Increased usability: The suggestion mechanism can assist users in quickly finding the relevant commands without the need to remember the exact function names.
  • Reduced confusion: By providing related commands, it can help users avoid frustration and save time looking for documentation.
  • Improved Python learning experience: Beginners will have a smoother experience when exploring Python’s functions and classes, making it easier to learn and use Python effectively.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

@bushraqurban bushraqurban added the type-feature A feature request or enhancement label Nov 26, 2024
@skirpichev
Copy link
Member

the response is simply

BTW, you might query for docs differently:

>>> help(abt)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    help(abt)
         ^^^
NameError: name 'abt' is not defined. Did you mean: 'abs'?
>>> help(abs)
Help on built-in function abs in module builtins:

abs(x, /)
    Return the absolute value of the argument.

This is a minor feature, which does not need previous discussion elsewhere

I doubt it's a minor feature. You examples demonstrate, that a "helper" for the help() will be assumed to do very non-trivial things, for external projects like Pandas - too. It's not clear (1) how exactly, (2) at which cost (there possible security, performance issues, etc).

IMO, this kind of stuff should be first discussed on the https://discuss.python.org/c/ideas/6. Preferably, with much more detailed proposal to show how this may work algorithmically.

@skirpichev skirpichev added the pending The issue will be closed if no feedback is provided label Nov 26, 2024
@bushraqurban
Copy link
Author

Thanks for your feedback! I really appreciate your input. I see your point about the complexity of implementing this feature, especially for third-party packages like Pandas. I’ll take some time to consider these issues more carefully, particularly how we can limit the scope of the suggestions to only trusted modules and imported libraries. I’m planning to explore solutions that balance usability and performance.

I’ll follow up with a more detailed proposal once I’ve thought through the details. Thanks again for your insights!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending The issue will be closed if no feedback is provided type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants