Skip to content

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

@bushraqurban

Description

@bushraqurban

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions