Skip to content

Commit 35ec03c

Browse files
authored
Tweak check for IPython pylab mode. (#23097)
We really only care about whether the attribute is present (even nowadays, _needmain is always False; it appears to never have changed in IPython's history).
1 parent feb1ca1 commit 35ec03c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/matplotlib/backend_bases.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -3498,14 +3498,11 @@ def show(cls, *, block=None):
34983498
if cls.mainloop is None:
34993499
return
35003500
if block is None:
3501-
# Hack: Are we in IPython's pylab mode?
3501+
# Hack: Are we in IPython's %pylab mode? In pylab mode, IPython
3502+
# (>= 0.10) tacks a _needmain attribute onto pyplot.show (always
3503+
# set to False).
35023504
from matplotlib import pyplot
3503-
try:
3504-
# IPython versions >= 0.10 tack the _needmain attribute onto
3505-
# pyplot.show, and always set it to False, when in %pylab mode.
3506-
ipython_pylab = not pyplot.show._needmain
3507-
except AttributeError:
3508-
ipython_pylab = False
3505+
ipython_pylab = hasattr(pyplot.show, "_needmain")
35093506
block = not ipython_pylab and not is_interactive()
35103507
# TODO: The above is a hack to get the WebAgg backend working with
35113508
# ipython's `%pylab` mode until proper integration is implemented.

0 commit comments

Comments
 (0)