python / python/cpython

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

オープン
#138,094 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

docs stdlib
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

_sitebuiltins.py で参照されている _Helper の実装から始め、対話型ヘルププロンプトが存在しないトピックと help(help) をどのように処理しているかを追跡します。対話モードで使用できない候補が表示されなくなり、help(help) が無関係なクラスの詳細を含めずに使用方法を示すようになれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli, documentation
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。