From e9c3333d4145bf631f0eae91514219479e1000ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Mon, 6 Mar 2023 14:38:34 -0300 Subject: [PATCH 1/2] Fix warning with ipython 8.11 --- src/sage/repl/inputhook.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sage/repl/inputhook.py b/src/sage/repl/inputhook.py index da5df0268c0..165068da8bc 100644 --- a/src/sage/repl/inputhook.py +++ b/src/sage/repl/inputhook.py @@ -47,15 +47,25 @@ def install(): """ Install the Sage input hook - EXAMPLES:: + EXAMPLES: + + Make sure ipython is running so we really test this function:: + + sage: from sage.repl.interpreter import get_test_shell + sage: get_test_shell() + + + Run the function twice, to check it is idempotent (see :trac:`35235`):: sage: from sage.repl.inputhook import install sage: install() + sage: install() """ ip = get_ipython() if not ip: return # Not running in ipython, e.g. doctests - ip.enable_gui('sage') + if ip._inputhook != sage_inputhook: + ip.enable_gui('sage') def uninstall(): From 45b651e95a0ea43a3246a18755ccd44604d813ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sun, 2 Apr 2023 17:57:53 -0300 Subject: [PATCH 2/2] silence useless output with ipython 8.12 --- src/sage/repl/inputhook.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sage/repl/inputhook.py b/src/sage/repl/inputhook.py index 165068da8bc..7f7894f6dcf 100644 --- a/src/sage/repl/inputhook.py +++ b/src/sage/repl/inputhook.py @@ -17,6 +17,8 @@ import select import errno +import contextlib +import io from IPython import get_ipython from IPython.terminal.pt_inputhooks import register @@ -65,7 +67,9 @@ def install(): if not ip: return # Not running in ipython, e.g. doctests if ip._inputhook != sage_inputhook: - ip.enable_gui('sage') + # silence `ip.enable_gui()` useless output + with contextlib.redirect_stdout(io.StringIO()): + ip.enable_gui('sage') def uninstall(): @@ -81,4 +85,6 @@ def uninstall(): if not ip: return if ip._inputhook == sage_inputhook: - ip.enable_gui(None) + # silence `ip.enable_gui()` useless output + with contextlib.redirect_stdout(io.StringIO()): + ip.enable_gui(None)