make sure the builtin help function doesn't fail when sys.stdin is not a valid file (closes #11709)
Original patch by Amaury Forgeot d'Arc with a test by bdettmer.
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 254fe40..218fd30 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1377,6 +1377,8 @@
"""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:
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index 7ff8d6d..763c319 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -333,6 +333,14 @@
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