Skip to content

Commit

Permalink
Darken and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Apr 2, 2024
1 parent 6b57c1a commit 72be620
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions IPython/core/magics/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#-----------------------------------------------------------------------------

magic_gui_arg = magic_arguments.argument(
'gui', nargs='?',
help="""Name of the matplotlib backend to use such as 'qt' or 'widget'.
"gui",
nargs="?",
help="""Name of the matplotlib backend to use such as 'qt' or 'widget'.
If given, the corresponding matplotlib backend is used,
otherwise it will be matplotlib's default
(which you can set in your matplotlib config file).
"""
""",
)


Expand Down Expand Up @@ -93,11 +94,14 @@ def matplotlib(self, line=''):
args = magic_arguments.parse_argstring(self.matplotlib, line)
if args.list:
from IPython.core.pylabtools import _matplotlib_manages_backends

if _matplotlib_manages_backends():
from matplotlib.backends.registry import backend_registry

backends_list = backend_registry.list_all()
else:
from IPython.core.pylabtools import backends

backends_list = list(backends.keys())
print("Available matplotlib backends: %s" % backends_list)
else:
Expand Down
13 changes: 9 additions & 4 deletions IPython/core/pylabtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
# GUI support to activate based on the desired matplotlib backend. For the
# most part it's just a reverse of the above dict, but we also need to add a
# few others that map to the same GUI manually:
_deprecated_backend2gui = dict(zip(_deprecated_backends.values(), _deprecated_backends.keys()))
_deprecated_backend2gui = dict(
zip(_deprecated_backends.values(), _deprecated_backends.keys())
)
# In the reverse mapping, there are a few extra valid matplotlib backends that
# map to the same GUI support
_deprecated_backend2gui["GTK"] = _deprecated_backend2gui["GTKCairo"] = "gtk"
Expand Down Expand Up @@ -279,7 +281,7 @@ def select_figure_formats(shell, formats, **kwargs):

[ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ]
mplbackend = matplotlib.get_backend().lower()
if mplbackend in ('nbagg', 'ipympl', 'widget', 'module://ipympl.backend_nbagg'):
if mplbackend in ("nbagg", "ipympl", "widget", "module://ipympl.backend_nbagg"):
formatter = shell.display_formatter.ipython_display_formatter
formatter.for_type(Figure, _reshow_nbagg_figure)

Expand Down Expand Up @@ -330,15 +332,16 @@ def find_gui_and_backend(gui=None, gui_select=None):
"""

import matplotlib

if _matplotlib_manages_backends():
backend_registry = matplotlib.backends.registry.backend_registry

# gui argument may be a gui event loop or may be a backend name.
if gui in ("auto", None):
backend = matplotlib.rcParamsOrig['backend']
backend = matplotlib.rcParamsOrig["backend"]
backend, gui = backend_registry.resolve_backend(backend)
else:
backend, gui = backend_registry.resolve_gui_or_backend(gui)
backend, gui = backend_registry.resolve_gui_or_backend(gui)

return gui, backend

Expand All @@ -347,6 +350,7 @@ def find_gui_and_backend(gui=None, gui_select=None):
has_unified_qt_backend = mpl_version_info >= (3, 5)

from IPython.core.pylabtools import backends

backends_ = dict(backends)
if not has_unified_qt_backend:
backends_["qt"] = "qt5agg"
Expand Down Expand Up @@ -466,5 +470,6 @@ def configure_inline_support(shell, backend):

def _matplotlib_manages_backends():
import matplotlib

mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0))
return mpl_version_info >= (3, 9)
2 changes: 1 addition & 1 deletion IPython/core/shellapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases))

backend_keys = []
backend_keys: list[str] = []

shell_flags = {}

Expand Down

0 comments on commit 72be620

Please sign in to comment.