]> 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 254fe409f5027d97d67a49360e9fd93541406e35..218fd30d50e93aa36556f7183b31c1a1012c4795 100755 (executable)
@@ -1377,6 +1377,8 @@ def getpager():
     """Decide what method to use for paging through text."""
     if type(sys.stdout) is not types.FileType:
         return plainpager
+    if not hasattr(sys.stdin, "isatty"):
+        return plainpager
     if not sys.stdin.isatty() or not sys.stdout.isatty():
         return plainpager
     if 'PAGER' in os.environ:
index 7ff8d6de43c17ff6eff267f26c7c6c7bcc562bbc..763c31915a7194dcf39a3540823dffa995809546 100644 (file)
@@ -333,6 +333,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 155811eef73e2bf4b3a1a89267fc8330229eac27..e3827bbb1a8137ea5c281acab39deec89527ab62 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,9 @@ Library
 - Issue #21304: Backport the key derivation function hashlib.pbkdf2_hmac from
   Python 3 per PEP 466.
 
+- 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.