Skip to content

Commit fa92cf9

Browse files
authored
Merge pull request #25870 from turnipseason/bug-fix-for-issue-23770
Adds error handling around install_repl_displayhook
2 parents 8ac84ec + 321b769 commit fa92cf9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/matplotlib/pyplot.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,11 @@ def draw_if_interactive() -> None:
520520
matplotlib.backends.backend = newbackend # type: ignore[attr-defined]
521521

522522
# Make sure the repl display hook is installed in case we become interactive.
523-
install_repl_displayhook()
523+
try:
524+
install_repl_displayhook()
525+
except NotImplementedError as err:
526+
_log.warning("Fallback to a different backend")
527+
raise ImportError from err
524528

525529

526530
def _warn_if_gui_out_of_main_thread() -> None:

lib/matplotlib/tests/test_backends_interactive.py

+15
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,21 @@ def test_blitting_events(env):
629629
assert 0 < ndraws < 5
630630

631631

632+
def _fallback_check():
633+
import IPython.core.interactiveshell as ipsh
634+
import matplotlib.pyplot
635+
ipsh.InteractiveShell.instance()
636+
matplotlib.pyplot.figure()
637+
638+
639+
def test_fallback_to_different_backend():
640+
pytest.importorskip("IPython")
641+
# Runs the process that caused the GH issue 23770
642+
# making sure that this doesn't crash
643+
# since we're supposed to be switching to a different backend instead.
644+
response = _run_helper(_fallback_check, timeout=_test_timeout)
645+
646+
632647
def _impl_test_interactive_timers():
633648
# A timer with <1 millisecond gets converted to int and therefore 0
634649
# milliseconds, which the mac framework interprets as singleshot.

0 commit comments

Comments
 (0)