]> granicus.if.org Git - python/commitdiff
make sure the builtin help function doesn't fail when sys.stdin is not a valid file...
authorBenjamin Peterson <benjamin@python.org>
Sun, 8 Jun 2014 03:14:26 +0000 (20:14 -0700)
committerBenjamin Peterson <benjamin@python.org>
Sun, 8 Jun 2014 03:14:26 +0000 (20:14 -0700)
Original patch by Amaury Forgeot d'Arc with a test by bdettmer.

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

index 2dee6eee23d40f1835c7427a1edc435107daf234..cc43684f191442f5f31d36e45b2caeaa02cadf0b 100755 (executable)
@@ -1417,6 +1417,8 @@ def pager(text):
 
 def getpager():
     """Decide what method to use for paging through text."""
+    if not hasattr(sys.stdin, "isatty"):
+        return plainpager
     if not hasattr(sys.stdout, "isatty"):
         return plainpager
     if not sys.stdin.isatty() or not sys.stdout.isatty():
index 188c4c26feb8f0d30d2a6915eedf3bd7c6c75880..542b433cb6ecdebbc4da028083f1c0a89a843429 100644 (file)
@@ -446,6 +446,14 @@ class PydocDocTest(unittest.TestCase):
         result, doc_loc = get_pydoc_text(xml.etree)
         self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
 
+    def test_getpager_with_stdin_none(self):
+        previous_stdin = sys.stdin
+        try:
+            sys.stdin = None
+            pydoc.getpager() # Shouldn't fail.
+        finally:
+            sys.stdin = previous_stdin
+
     def test_non_str_name(self):
         # issue14638
         # Treat illegal (non-str) name like no name
index 57090b65624f0df20ae69b95daf65c0bed6ab790..6979b2f107cd16e84938756680f79a890926b71e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a
+  valid file.
+
 - Issue #13223: Fix pydoc.writedoc so that the HTML documentation for methods
   that use 'self' in the example code is generated correctly.