diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index 1524fccd5d20f8..540c12230cf2cf 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -938,11 +938,9 @@ def __init__(self, flist=None): sys.stderr = self.stderr sys.stdin = self.stdin try: - # page help() text to shell. - import pydoc # import must be done here to capture i/o rebinding. - # XXX KBK 27Dec07 use text viewer someday, but must work w/o subproc - pydoc.pager = pydoc.plainpager - except: + import pydoc # import must be done here to capture i/o rebinding. + pydoc.pager = self.pager + except Exception: sys.stderr = sys.__stderr__ raise # @@ -984,6 +982,16 @@ def replace_event(self, event): replace.replace(self.text, insert_tags="stdin") return "break" + def pager(self, text): + """pydoc.pager compatible callback for showing help() output.""" + import pydoc # Import here to avoid i/o binding issues. + text = pydoc.plain(text) # Remove fancy pydoc formatting. + try: + title, text = text.split(':\n\n', 1) + except ValueError: + title = "Help" + view_text(self.text, title, text, modal=False) + def get_standard_extension_names(self): return idleConf.GetExtensions(shell_only=True) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 53e80a9b42801f..5d89858d32875d 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -530,9 +530,8 @@ def handle(self): iomenu.encoding, "backslashreplace") sys.displayhook = rpc.displayhook - # page help() text to shell. - import pydoc # import must be done here to capture i/o binding - pydoc.pager = pydoc.plainpager + import pydoc # import must be done here to capture i/o binding + pydoc.pager = self.console.pager # Keep a reference to stdin so that it won't try to exit IDLE if # sys.stdin gets changed from within IDLE's shell. See issue17838. diff --git a/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst b/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst new file mode 100644 index 00000000000000..9d7ef892fe0961 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst @@ -0,0 +1,2 @@ +``help(object)`` now shows the help text in a separate text viewing window +rather than in the shell output.