8000 Smaller review changes · matplotlib/matplotlib@0d8c471 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d8c471

Browse files
committed
Smaller review changes
1 parent bc5d384 commit 0d8c471

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,7 @@ def _switch_canvas_and_return_print_method(self, fmt, backend=None):
20392039
if backend is not None:
20402040
# Return a specific canvas class, if requested.
20412041
from .backends.registry import backend_registry
2042-
canvas_class = (
2043-
backend_registry.load_backend_module(backend).FigureCanvas)
2042+
canvas_class = backend_registry.load_backend_module(backend).FigureCanvas
20442043
if not hasattr(canvas_class, f"print_{fmt}"):
20452044
raise ValueError(
20462045
f"The {backend!r} backend does not support {fmt} output")

lib/matplotlib/backends/registry.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def _backend_module_name(self, backend):
9898
backend = backend.lower()
9999

100100
# Check if have specific name to module mapping.
101-
backend = self._name_to_module.get(backend) or backend
101+
backend = self._name_to_module.get(backend, backend)
102102

103103
return (backend[9:] if backend.startswith("module://")
104-
else f"matplotlib.backends.backend_{backend.lower()}")
104+
else f"matplotlib.backends.backend_{backend}")
105105

106106
def _clear(self):
107107
# Clear all dynamically-added data, used for testing only.
@@ -136,7 +136,7 @@ def _read_entry_points(self):
136136
if sys.version_info >= (3, 10):
137137
entry_points = im.entry_points(group=group)
138138
else:
139-
entry_points = im.entry_points().get(group, {})
139+
entry_points = im.entry_points().get(group, ())
140140
entries = [(entry.name, entry.value) for entry in entry_points]
141141

142142
# For backward compatibility, if matplotlib-inline and/or ipympl are installed
@@ -199,7 +199,7 @@ def backend_for_gui_framework(self, framework):
199199
"""
200200
return self._GUI_FRAMEWORK_TO_BACKEND.get(framework.lower())
201201

202-
def is_valid_backend(self, backend: str) -> bool:
202+
def is_valid_backend(self, backend):
203203
"""
204204
Return True if the backend name is valid, False otherwise.
205205
@@ -262,7 +262,7 @@ def list_all(self):
262262
Backend names.
263263
"""
264264
self._ensure_entry_points_loaded()
265-
return self.list_builtin() + list(self._backend_to_gui_framework.keys())
265+
return [*self.list_builtin(), *self._backend_to_gui_framework]
266266

267267
def list_builtin(self, filter_=None):
268268
"""
@@ -286,19 +286,18 @@ def list_builtin(self, filter_=None):
286286
return [k for k, v in self._BUILTIN_BACKEND_TO_GUI_FRAMEWORK.items()
287287
if v == "headless"]
288288

289-
return list(self._BUILTIN_BACKEND_TO_GUI_FRAMEWORK.keys())
289+
return [*self._BUILTIN_BACKEND_TO_GUI_FRAMEWORK]
290290

291291
def list_gui_frameworks(self):
292292
"""
293-
Return list of gui frameworks used by Matplotlib backends.
293+
Return list of GUI frameworks used by Matplotlib backends.
294294
295295
Returns
296296
-------
297297
list of str
298298
GUI framework names.
299299
"""
300-
return [k for k in self._GUI_FRAMEWORK_TO_BACKEND.keys()
301-
if k != "headless"]
300+
return [k for k in self._GUI_FRAMEWORK_TO_BACKEND if k != "headless"]
302301

303302
def load_backend_module(self, backend):
304303
"""
@@ -321,7 +320,7 @@ def resolve_backend(self, backend):
321320
"""
322321
Return the backend and GUI framework for the specified backend name.
323322
324-
If the GUI framework is not yet known then it will be determine by loading the
323+
If the GUI framework is not yet known then it will be determined by loading the
325324
backend module and checking the ``FigureCanvas.required_interactive_framework``
326325
attribute.
327326
@@ -351,8 +350,7 @@ def resolve_backend(self, backend):
351350
self._backend_to_gui_framework.get(backend))
352351

353352
# Is backend "module://something"?
354-
if (gui is None and isinstance(backend, str) and
355-
backend.startswith("module://")):
353+
if gui is None and isinstance(backend, str) and backend.startswith("module://"):
356354
gui = "unknown"
357355

358356
# Is backend a possible entry point?
@@ -389,7 +387,7 @@ def resolve_gui_or_backend(self, gui_or_backend):
389387
390388
Returns
391389
-------
392-
Tuple of backend (str) and GUI framework (str or None).
390+
tuple of (str, str or None)
393391
A non-interactive backend returns None for its GUI framework rather than
394392
"headless".
395393
"""

0 commit comments

Comments
 (0)
0