`help` function: misleading output in interactive mode, confusing output for `help(help)`
还没有人认领这个 Issue。
- 主要语言
- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 _sitebuiltins.py 中引用的 _Helper 实现开始,跟踪交互式帮助提示如何处理缺失主题和 help(help)。完成标准是:交互模式不再显示无法使用的建议,并且 help(help) 提供用法说明而不包含无关的类详细信息。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- cli, documentation
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100