Skip to content

bpo-13691: Fixes pydoc help (or help('help')) to show the doc for help #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/_sitebuiltins.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class _Helper(object):
def __repr__(self):
return "Type help() for interactive help, " \
"or help(object) for help about object."

def __call__(self, *args, **kwds):
import pydoc
return pydoc.help(*args, **kwds)
23 changes: 23 additions & 0 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,11 +1917,30 @@ def getline(self, prompt):
return self.input.readline()

def help(self, request):
"""Help on built-in function help:

help(...)
Invoke the built-in help system.

help()
The interactive help system starts on the interpreter
console.

help(string)
The string is looked up as the name of a module, function, class, method,
keyword, or documentation topic, and a help page is printed on the
console.

help(object)
Generates a help page on the given object.
"""
from _sitebuiltins import _Helper
if type(request) is type(''):
request = request.strip()
if request == 'keywords': self.listkeywords()
elif request == 'symbols': self.listsymbols()
elif request == 'topics': self.listtopics()
elif request == 'help': self.showhelp()
elif request == 'modules': self.listmodules()
elif request[:8] == 'modules ':
self.listmodules(request.split()[1])
Expand All @@ -1934,6 +1953,7 @@ def help(self, request):
elif request: doc(request, 'Help on %s:', output=self._output)
else: doc(str, 'Help on %s:', output=self._output)
elif isinstance(request, Helper): self()
elif isinstance(request, _Helper): self.showhelp()
else: doc(request, 'Help on %s:', output=self._output)
self.output.write('\n')

Expand Down Expand Up @@ -1967,6 +1987,9 @@ def list(self, items, columns=4, width=80):
self.output.write(' ' + ' ' * (colw - 1 - len(items[i])))
self.output.write('\n')

def showhelp(self):
self.output.write(self.help.__doc__)

def listkeywords(self):
self.output.write('''
Here is a list of the Python keywords. Enter any keyword to get more help.
Expand Down