python / python/cpython

`help` function: misleading output in interactive mode, confusing output for `help(help)`

Offen
#138,094 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

docs stdlib
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

When using the built-in help function in interactive mode, the current output when no topic is found is potentially misleading, in that the suggestions offered are not usable at the interactive help prompt, e.g.:

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

Typing either of the suggested expressions at the help prompt will, of course, not work, because they're meant for use in Python code. And the suggestion about str seems to be irrelevant in interactive mode, where everything is a string anyway. I think it would be better not to offer these suggestions at all when running in interactive mode.

Additionally, running help(help) shows a large amount of irrelevant information related to the _Helper class from _sitebuiltins.py, with the usage instructions buried inside of it:

Output of help(help)
Help on _Helper in module _sitebuiltins object:

class _Helper(builtins.object)
 |  Define the builtin 'help'.
 |
 |  This is a wrapper around pydoc.help that provides a helpful message
 |  when 'help' is typed at the Python interactive prompt.
 |
 |  Calling help() at the Python prompt starts an interactive help session.
 |  Calling help(thing) prints help for the python object 'thing'.
 |
 |  Methods defined here:
 |
 |  __call__(self, *args, **kwds)
 |      Call self as a function.
 |
 |  __repr__(self)
 |      Return repr(self).
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object

I think this could be improved by showing usage instructions when invoking help(help) from Python, but preserving the current behavior of repeating the intro text when looking up help via the interactive prompt.

I'll put in a PR shortly that attempts to improve both of these.

Linked PRs
  • gh-138095

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der in _sitebuiltins.py referenzierten _Helper-Implementierung und verfolge, wie die interaktive Hilfeaufforderung mit fehlenden Themen und help(help) umgeht. Als erledigt gilt die Aufgabe, wenn der interaktive Modus keine unbrauchbaren Vorschläge mehr anzeigt und help(help) Nutzungsanweisungen ohne die irrelevanten Klassendetails präsentiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
cli, documentation
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.