Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 159824e

Browse files
committed
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.
1 parent 96e0430 commit 159824e

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/pydoc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,8 @@ def pager(text):
14171417

14181418
def getpager():
14191419
"""Decide what method to use for paging through text."""
1420+
if not hasattr(sys.stdin, "isatty"):
1421+
return plainpager
14201422
if not hasattr(sys.stdout, "isatty"):
14211423
return plainpager
14221424
if not sys.stdin.isatty() or not sys.stdout.isatty():

Lib/test/test_pydoc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ def test_issue8225(self):
446446
result, doc_loc = get_pydoc_text(xml.etree)
447447
self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
448448

449+
def test_getpager_with_stdin_none(self):
450+
previous_stdin = sys.stdin
451+
try:
452+
sys.stdin = None
453+
pydoc.getpager() # Shouldn't fail.
454+
finally:
455+
sys.stdin = previous_stdin
456+
449457
def test_non_str_name(self):
450458
# issue14638
451459
# Treat illegal (non-str) name like no name

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Core and Builtins
2222
Library
2323
-------
2424

25+
- Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a
26+
valid file.
27+
2528
- Issue #13223: Fix pydoc.writedoc so that the HTML documentation for methods
2629
that use 'self' in the example code is generated correctly.
2730

0 commit comments

Comments
 (0)