Skip to content

Commit 93ac0fa

Browse files
committed
better help for built-in help function
1 parent b36972d commit 93ac0fa

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

Lib/pydoc.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class or function within a module or module in a package. If the
7878
from reprlib import Repr
7979
from traceback import format_exception_only
8080

81+
import _sitebuiltins
82+
8183
from _pyrepl.pager import (get_pager, pipe_pager,
8284
plain_pager, tempfile_pager, tty_pager)
8385

@@ -1832,10 +1834,10 @@ def _introdoc():
18321834
Python, you should definitely check out the tutorial at
18331835
https://docs.python.org/{ver}/tutorial/.
18341836
1835-
Enter the name of any module, keyword, or topic to get help on writing
1836-
Python programs and using Python modules. To get a list of available
1837-
modules, keywords, symbols, or topics, enter "modules", "keywords",
1838-
"symbols", or "topics".
1837+
Enter the name of any module, keyword, symbol, or topic to get help on
1838+
writing Python programs and using Python modules. To get a list of
1839+
available modules, keywords, symbols, or topics, enter "modules",
1840+
"keywords", "symbols", or "topics".
18391841
{pyrepl_keys}
18401842
Each module also comes with a one-line summary of what it does; to list
18411843
the modules whose name or summary contain a given string such as "spam",
@@ -2092,7 +2094,9 @@ def getline(self, prompt):
20922094
def help(self, request, is_cli=False):
20932095
if isinstance(request, str):
20942096
request = request.strip()
2095-
if request == 'keywords': self.listkeywords()
2097+
if request == 'help':
2098+
self.helphelp()
2099+
elif request == 'keywords': self.listkeywords()
20962100
elif request == 'symbols': self.listsymbols()
20972101
elif request == 'topics': self.listtopics()
20982102
elif request == 'modules': self.listmodules()
@@ -2106,10 +2110,33 @@ def help(self, request, is_cli=False):
21062110
elif request in self.topics: self.showtopic(request)
21072111
elif request: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
21082112
else: doc(str, 'Help on %s:', output=self._output, is_cli=is_cli)
2109-
elif isinstance(request, Helper): self()
2113+
elif request is builtins.help:
2114+
self.helphelp()
21102115
else: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
21112116
self.output.write('\n')
21122117

2118+
def helphelp(self):
2119+
pager(textwrap.dedent("""\
2120+
help - Interactive Help
2121+
=======================
2122+
2123+
The built-in help function implements an interactive help utility. You
2124+
can make use of it in a few different ways:
2125+
2126+
* Calling help() with no arguments starts an interactive help session.
2127+
2128+
* Calling help(x) will have one of two behaviors depending on the type
2129+
of the argument:
2130+
2131+
* If x is a string, help(x) provides information about the given
2132+
topic. For example, help("class") will provide information about
2133+
the "class" keyword, and help("math.sqrt") will provide
2134+
information about the "math.sqrt" function.
2135+
2136+
* If x is not a string, help(x) prints information about x's type.
2137+
For example, help(20) will provide information about the int type.
2138+
"""))
2139+
21132140
def intro(self):
21142141
self.output.write(_introdoc())
21152142

0 commit comments

Comments
 (0)