changeset: 91081:1a9c07880a15 branch: 2.7 parent: 91078:a0be81607a50 user: Benjamin Peterson date: Sat Jun 07 20:14:26 2014 -0700 files: Lib/pydoc.py Lib/test/test_pydoc.py Misc/NEWS description: 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 -r a0be81607a50 -r 1a9c07880a15 Lib/pydoc.py --- a/Lib/pydoc.py Sat Jun 07 17:57:36 2014 -0700 +++ b/Lib/pydoc.py Sat Jun 07 20:14:26 2014 -0700 @@ -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 -r a0be81607a50 -r 1a9c07880a15 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Sat Jun 07 17:57:36 2014 -0700 +++ b/Lib/test/test_pydoc.py Sat Jun 07 20:14:26 2014 -0700 @@ -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 diff -r a0be81607a50 -r 1a9c07880a15 Misc/NEWS --- a/Misc/NEWS Sat Jun 07 17:57:36 2014 -0700 +++ b/Misc/NEWS Sat Jun 07 20:14:26 2014 -0700 @@ -28,6 +28,9 @@ - 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.