]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19980: Improved help() for non-recognized strings. help('') now
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Feb 2015 22:42:54 +0000 (00:42 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Feb 2015 22:42:54 +0000 (00:42 +0200)
shows the help on str.  help('help') now shows the help on help().
Original patch by Mark Lawrence.

Lib/pydoc.py
Lib/test/test_pydoc.py
Misc/ACKS
Misc/NEWS

index b762389cf3a6eeeeaee3da4d58d26283e150aaf4..c92b324afd26cb5b04d3304f58485e87a5d0c58f 100755 (executable)
@@ -1577,7 +1577,10 @@ def resolve(thing, forceload=0):
     if isinstance(thing, str):
         object = locate(thing, forceload)
         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
     else:
         name = getattr(thing, '__name__', None)
@@ -1848,7 +1851,10 @@ has the same effect as typing a particular string at the help> prompt.
                 break
             request = replace(request, '"', '', "'", '').strip()
             if request.lower() in ('q', 'quit'): break
-            self.help(request)
+            if request == 'help':
+                self.intro()
+            else:
+                self.help(request)
 
     def getline(self, prompt):
         """Read one line, using input() when appropriate."""
@@ -1862,8 +1868,7 @@ has the same effect as typing a particular string at the help> prompt.
     def help(self, request):
         if type(request) is type(''):
             request = request.strip()
-            if request == 'help': self.intro()
-            elif request == 'keywords': self.listkeywords()
+            if request == 'keywords': self.listkeywords()
             elif request == 'symbols': self.listsymbols()
             elif request == 'topics': self.listtopics()
             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.topics: self.showtopic(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()
         else: doc(request, 'Help on %s:', output=self._output)
         self.output.write('\n')
index e9fed0ad1681958788d2128a119cc6ea4dde6018..edfdb66497e4a9d67bb21933428c85fb51387e35 100644 (file)
@@ -256,7 +256,10 @@ expected_html_data_docstrings = tuple(s.replace(' ', '&nbsp;')
                                       for s in expected_data_docstrings)
 
 # 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
 badimport_pattern = "problem in %s - ImportError: No module named %r"
index 861216e7d09414bd701824ff3490f35c016f6d9c..7707f67e317921881f78c99759641e3272ea157b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -789,6 +789,7 @@ Ben Laurie
 Simon Law
 Julia Lawall
 Chris Lawrence
+Mark Lawrence
 Brian Leair
 Mathieu Leduc-Hamel
 Amandine Lee
index e9560e370b3510869a0d16daa9ceeaf825094978..f1a1410191717fb51264f4094625bb0c813fb2da 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@ Core and Builtins
 
 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.
 
  * Eliminated OverflowError from timedelta * float for some floats;