[Python-checkins] cpython: Issue #19980: Improved help() for non-recognized strings. help('') now

serhiy.storchaka python-checkins at python.org
Sat Feb 28 23:43:41 CET 2015


https://hg.python.org/cpython/rev/4a1fe339dcf6
changeset:   94790:4a1fe339dcf6
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Mar 01 00:42:54 2015 +0200
summary:
  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.

files:
  Lib/pydoc.py           |  14 ++++++++++----
  Lib/test/test_pydoc.py |   5 ++++-
  Misc/ACKS              |   1 +
  Misc/NEWS              |   5 +++++
  4 files changed, 20 insertions(+), 5 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1577,7 +1577,10 @@
     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 @@
                 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 @@
     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 @@
             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')
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -256,7 +256,10 @@
                                       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"
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -789,6 +789,7 @@
 Simon Law
 Julia Lawall
 Chris Lawrence
+Mark Lawrence
 Brian Leair
 Mathieu Leduc-Hamel
 Amandine Lee
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@
 
 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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list