Skip to content

Add more useful help for special name in help() #137574

Open

Description

@Locked-chess-official

Feature or enhancement

Proposal:

Now, use help("__name__") and some other special variables' names will still get the help from their class. I think that we can add the useful help on them. For example:

>>>help("__name__")
1. module.__name__ : if the module is run as the main module, the value is ‘_main_‘, or the name is the filename of the module. For example:if __name__ == "__main__": ...can control which code don’t run when the module is imported.

2. cls.__name__: the name of the class. It must be str.

For other special variables (such as __file__), we can alse print the similar detailed help. And I think that the sentences need to be friendly.

Also welcome to give the ideals on new ideas

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. terryjreedy commented on Aug 9, 2025

    @terryjreedy
    Member

    https://discuss.python.org/t/function-help-to-some-special-words/101625 I there suggested the alternative:

    help has an interactive mode, entered with help(), in which one can enter an unquoted word (module, keyword, or topic), symbol (such as .) to get specific help, or “modules”, “keywords”,
    “symbols”, or “topics” for a list of those available. It would be plausible to request that special (double-underscored, dunder) names be recognized, with “dunders” or “specials” returning a list of those recognized. In particular, help> name could give a purpose-written entry similar to that proposed above.

    I believe that there have been multiple requests that help('whatever') check for special help on whatever before spewing out the 400+ pages of help on str (and without having to enter interactive help). The latter is easily available with help(''). The would, however, be a larger change.

  2. StanFromIreland commented on Aug 9, 2025

    @StanFromIreland
    Member

    This old deferred PEP may be of interest: PEP 233

  3. serhiy-storchaka commented on Aug 9, 2025

    @serhiy-storchaka
    Member

    I believe that there have been multiple requests that help('whatever') check for special help on whatever before spewing out the 400+ pages of help on str

    It does. Try help("<") or help("int") or help("re").

    But I think that it would better to stop falling back to the str class help for every other string. Better to output an error, maybe with a suggestion as for other typos.

  4. adqm commented on Aug 11, 2025

    @adqm
    Contributor

    But I think that it would better to stop falling back to the str class help for every other string. Better to output an error, maybe with a suggestion as for other typos.

    It looks like this already happens in many (but not all) cases, e.g.:

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

    help("__main__") takes me to some useful docs, but help("__name__") tells me about str.

    I'd be happy to have a go at this if no one else is working on it yet.

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

    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