mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #19980: Improved help() for non-recognized strings. help('') now
shows the help on str. help('help') now shows the help on help(). Original patch by Mark Lawrence.
This commit is contained in:
parent
e92951f8da
commit
1c205518a3
4 changed files with 20 additions and 5 deletions
12
Lib/pydoc.py
12
Lib/pydoc.py
|
@ -1577,7 +1577,10 @@ def resolve(thing, forceload=0):
|
||||||
if isinstance(thing, str):
|
if isinstance(thing, str):
|
||||||
object = locate(thing, forceload)
|
object = locate(thing, forceload)
|
||||||
if not object:
|
if not object:
|
||||||
raise ImportError('no Python documentation found for %r' % thing)
|
raise ImportError('''\
|
||||||
|
No Python documentation found for %r.
|
||||||
|
Use help() to get the interactive help utility.
|
||||||
|
Use help(str) for help on the str class.''' % thing)
|
||||||
return object, thing
|
return object, thing
|
||||||
else:
|
else:
|
||||||
name = getattr(thing, '__name__', None)
|
name = getattr(thing, '__name__', None)
|
||||||
|
@ -1848,6 +1851,9 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
break
|
break
|
||||||
request = replace(request, '"', '', "'", '').strip()
|
request = replace(request, '"', '', "'", '').strip()
|
||||||
if request.lower() in ('q', 'quit'): break
|
if request.lower() in ('q', 'quit'): break
|
||||||
|
if request == 'help':
|
||||||
|
self.intro()
|
||||||
|
else:
|
||||||
self.help(request)
|
self.help(request)
|
||||||
|
|
||||||
def getline(self, prompt):
|
def getline(self, prompt):
|
||||||
|
@ -1862,8 +1868,7 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
def help(self, request):
|
def help(self, request):
|
||||||
if type(request) is type(''):
|
if type(request) is type(''):
|
||||||
request = request.strip()
|
request = request.strip()
|
||||||
if request == 'help': self.intro()
|
if request == 'keywords': self.listkeywords()
|
||||||
elif request == 'keywords': self.listkeywords()
|
|
||||||
elif request == 'symbols': self.listsymbols()
|
elif request == 'symbols': self.listsymbols()
|
||||||
elif request == 'topics': self.listtopics()
|
elif request == 'topics': self.listtopics()
|
||||||
elif request == 'modules': self.listmodules()
|
elif request == 'modules': self.listmodules()
|
||||||
|
@ -1876,6 +1881,7 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
elif request in self.keywords: self.showtopic(request)
|
elif request in self.keywords: self.showtopic(request)
|
||||||
elif request in self.topics: self.showtopic(request)
|
elif request in self.topics: self.showtopic(request)
|
||||||
elif request: doc(request, 'Help on %s:', output=self._output)
|
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()
|
||||||
else: doc(request, 'Help on %s:', output=self._output)
|
else: doc(request, 'Help on %s:', output=self._output)
|
||||||
self.output.write('\n')
|
self.output.write('\n')
|
||||||
|
|
|
@ -256,7 +256,10 @@ expected_html_data_docstrings = tuple(s.replace(' ', ' ')
|
||||||
for s in expected_data_docstrings)
|
for s in expected_data_docstrings)
|
||||||
|
|
||||||
# output pattern for missing module
|
# output pattern for missing module
|
||||||
missing_pattern = "no Python documentation found for '%s'"
|
missing_pattern = '''\
|
||||||
|
No Python documentation found for %r.
|
||||||
|
Use help() to get the interactive help utility.
|
||||||
|
Use help(str) for help on the str class.'''.replace('\n', os.linesep)
|
||||||
|
|
||||||
# output pattern for module with bad imports
|
# output pattern for module with bad imports
|
||||||
badimport_pattern = "problem in %s - ImportError: No module named %r"
|
badimport_pattern = "problem in %s - ImportError: No module named %r"
|
||||||
|
|
|
@ -789,6 +789,7 @@ Ben Laurie
|
||||||
Simon Law
|
Simon Law
|
||||||
Julia Lawall
|
Julia Lawall
|
||||||
Chris Lawrence
|
Chris Lawrence
|
||||||
|
Mark Lawrence
|
||||||
Brian Leair
|
Brian Leair
|
||||||
Mathieu Leduc-Hamel
|
Mathieu Leduc-Hamel
|
||||||
Amandine Lee
|
Amandine Lee
|
||||||
|
|
|
@ -12,6 +12,11 @@ Core and Builtins
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #19980: Improved help() for non-recognized strings. help('') now
|
||||||
|
shows the help on str. help('help') now shows the help on help().
|
||||||
|
Original patch by Mark Lawrence.
|
||||||
|
|
||||||
- Issue #23521: Corrected pure python implementation of timedelta division.
|
- Issue #23521: Corrected pure python implementation of timedelta division.
|
||||||
|
|
||||||
* Eliminated OverflowError from timedelta * float for some floats;
|
* Eliminated OverflowError from timedelta * float for some floats;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue