Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cd9c1b

Browse filesBrowse files
authored
Merge pull request #24527 from anntzer/showoverride
Fix testing of whether backends use the new pyplot_show API.
2 parents f6e449b + f7043b6 commit 7cd9c1b
Copy full SHA for 7cd9c1b

File tree

Expand file treeCollapse file tree

4 files changed

+28
-18
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-18
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``backend_template.show``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... has been removed, in order to better demonstrate the new backend definition
4+
API.

‎lib/matplotlib/backends/backend_template.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_template.py
+3-13Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,13 @@ class GraphicsContextTemplate(GraphicsContextBase):
136136
########################################################################
137137

138138

139-
def show(*, block=None):
140-
"""
141-
For image backends - is not required.
142-
For GUI backends - show() is usually the last line of a pyplot script and
143-
tells the backend that it is time to draw. In interactive mode, this
144-
should do nothing.
145-
"""
146-
for manager in Gcf.get_all_fig_managers():
147-
# do something to display the GUI
148-
pass
149-
150-
151139
class FigureManagerTemplate(FigureManagerBase):
152140
"""
153141
Helper class for pyplot mode, wraps everything up into a neat bundle.
154142
155-
For non-interactive backends, the base class is sufficient.
143+
For non-interactive backends, the base class is sufficient. For
144+
interactive backends, see the documentation of the `.FigureManagerBase`
145+
class for the list of methods that can/should be overridden.
156146
"""
157147

158148

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,14 @@ def draw_if_interactive():
325325
# show is already present, as the latter may be here for backcompat.
326326
manager_class = getattr(getattr(backend_mod, "FigureCanvas", None),
327327
"manager_class", None)
328-
if (manager_class.pyplot_show != FigureManagerBase.pyplot_show
329-
or show is None):
328+
# We can't compare directly manager_class.pyplot_show and FMB.pyplot_show
329+
# because pyplot_show is a classmethod so the above constructs are bound
330+
# classmethods, & thus always different (being bound to different classes).
331+
manager_pyplot_show = vars(manager_class).get("pyplot_show")
332+
base_pyplot_show = vars(FigureManagerBase).get("pyplot_show")
333+
if (show is None
334+
or (manager_pyplot_show is not None
335+
and manager_pyplot_show != base_pyplot_show)):
330336
backend_mod.show = manager_class.pyplot_show
331337

332338
_log.debug("Loaded backend %s version %s.",

‎lib/matplotlib/tests/test_backend_template.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_template.py
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ def test_load_old_api(monkeypatch):
3232

3333
def test_show(monkeypatch):
3434
mpl_test_backend = SimpleNamespace(**vars(backend_template))
35-
mock_show = backend_template.FigureManagerTemplate.pyplot_show = \
36-
MagicMock()
37-
del mpl_test_backend.show
35+
mock_show = MagicMock()
36+
monkeypatch.setattr(
37+
mpl_test_backend.FigureManagerTemplate, "pyplot_show", mock_show)
38+
monkeypatch.setitem(sys.modules, "mpl_test_backend", mpl_test_backend)
39+
mpl.use("module://mpl_test_backend")
40+
plt.show()
41+
mock_show.assert_called_with()
42+
43+
44+
def test_show_old_global_api(monkeypatch):
45+
mpl_test_backend = SimpleNamespace(**vars(backend_template))
46+
mock_show = MagicMock()
47+
monkeypatch.setattr(mpl_test_backend, "show", mock_show, raising=False)
3848
monkeypatch.setitem(sys.modules, "mpl_test_backend", mpl_test_backend)
3949
mpl.use("module://mpl_test_backend")
4050
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.