Skip to content

Commit c20c0ac

Browse files
committed
Use class variables for immutable collections
1 parent acb7bf5 commit c20c0ac

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

lib/matplotlib/backends/registry.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,47 @@ class BackendRegistry:
1313
1414
This is the single source of truth for available backends.
1515
"""
16-
def __init__(self):
17-
# Built-in backends are those which are included in the Matplotlib repo.
18-
# A backend with name 'name' is located in the module
19-
# f'matplotlib.backends.backend_{name.lower()}'
20-
21-
# The capitalized forms are needed for ipython at present; this may
22-
# change for later versions.
23-
self._builtin_interactive = [
24-
"GTK3Agg", "GTK3Cairo", "GTK4Agg", "GTK4Cairo",
25-
"MacOSX",
26-
"nbAgg",
27-
"QtAgg", "QtCairo", "Qt5Agg", "Qt5Cairo",
28-
"TkAgg", "TkCairo",
29-
"WebAgg",
30-
"WX", "WXAgg", "WXCairo",
31-
]
32-
self._builtin_not_interactive = [
33-
"agg", "cairo", "pdf", "pgf", "ps", "svg", "template",
34-
]
35-
self._framework_to_backend_mapping = {
36-
"qt": "qtagg",
37-
"gtk3": "gtk3agg",
38-
"gtk4": "gtk4agg",
39-
"wx": "wxagg",
40-
"tk": "tkagg",
41-
"macosx": "macosx",
42-
"headless": "agg",
43-
}
16+
# Built-in backends are those which are included in the Matplotlib repo.
17+
# A backend with name 'name' is located in the module
18+
# f'matplotlib.backends.backend_{name.lower()}'
19+
20+
# The capitalized forms are needed for ipython at present; this may
21+
# change for later versions.
22+
_BUILTIN_INTERACTIVE = [
23+
"GTK3Agg", "GTK3Cairo", "GTK4Agg", "GTK4Cairo",
24+
"MacOSX",
25+
"nbAgg",
26+
"QtAgg", "QtCairo", "Qt5Agg", "Qt5Cairo",
27+
"TkAgg", "TkCairo",
28+
"WebAgg",
29+
"WX", "WXAgg", "WXCairo",
30+
]
31+
_BUILTIN_NOT_INTERACTIVE = [
32+
"agg", "cairo", "pdf", "pgf", "ps", "svg", "template",
33+
]
34+
_FRAMEWORK_TO_BACKEND_MAPPING = {
35+
"qt": "qtagg",
36+
"gtk3": "gtk3agg",
37+
"gtk4": "gtk4agg",
38+
"wx": "wxagg",
39+
"tk": "tkagg",
40+
"macosx": "macosx",
41+
"headless": "agg",
42+
}
4443

4544
def framework_to_backend(self, interactive_framework):
46-
return self._framework_to_backend_mapping.get(interactive_framework)
45+
return self._FRAMEWORK_TO_BACKEND_MAPPING.get(interactive_framework)
4746

4847
def list_builtin(self, filter_=None):
4948
if filter_ == BackendFilter.INTERACTIVE:
50-
return self._builtin_interactive
49+
return self._BUILTIN_INTERACTIVE
5150
elif filter_ == BackendFilter.INTERACTIVE_NON_WEB:
5251
return list(filter(lambda x: x.lower() not in ("webagg", "nbagg"),
53-
self._builtin_interactive))
52+
self._BUILTIN_INTERACTIVE))
5453
elif filter_ == BackendFilter.NON_INTERACTIVE:
55-
return self._builtin_not_interactive
54+
return self._BUILTIN_NOT_INTERACTIVE
5655

57-
return self._builtin_interactive + self._builtin_not_interactive
56+
return self._BUILTIN_INTERACTIVE + self._BUILTIN_NOT_INTERACTIVE
5857

5958

6059
# Singleton

0 commit comments

Comments
 (0)