From: Benjamin Peterson Date: Sun, 8 Jun 2014 03:14:26 +0000 (-0700) Subject: make sure the builtin help function doesn't fail when sys.stdin is not a valid file... X-Git-Tag: v3.4.2rc1~420 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=159824ea2a1872dadef69a229fb294c571d2ac73;p=python 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 2dee6eee23..cc43684f19 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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(): diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 188c4c26fe..542b433cb6 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index 57090b6562..6979b2f107 100644 --- 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.