File tree Expand file tree Collapse file tree 4 files changed +28
-18
lines changed
Filter options
doc/api/next_api_changes/removals Expand file tree Collapse file tree 4 files changed +28
-18
lines changed
Original file line number Diff line number Diff line change
1
+ ``backend_template.show ``
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
3
+ ... has been removed, in order to better demonstrate the new backend definition
4
+ API.
Original file line number Diff line number Diff line change @@ -136,23 +136,13 @@ class GraphicsContextTemplate(GraphicsContextBase):
136
136
########################################################################
137
137
138
138
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
-
151
139
class FigureManagerTemplate (FigureManagerBase ):
152
140
"""
153
141
Helper class for pyplot mode, wraps everything up into a neat bundle.
154
142
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.
156
146
"""
157
147
158
148
Original file line number Diff line number Diff line change @@ -325,8 +325,14 @@ def draw_if_interactive():
325
325
# show is already present, as the latter may be here for backcompat.
326
326
manager_class = getattr (getattr (backend_mod , "FigureCanvas" , None ),
327
327
"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 )):
330
336
backend_mod .show = manager_class .pyplot_show
331
337
332
338
_log .debug ("Loaded backend %s version %s." ,
Original file line number Diff line number Diff line change @@ -32,9 +32,19 @@ def test_load_old_api(monkeypatch):
32
32
33
33
def test_show (monkeypatch ):
34
34
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 )
38
48
monkeypatch .setitem (sys .modules , "mpl_test_backend" , mpl_test_backend )
39
49
mpl .use ("module://mpl_test_backend" )
40
50
plt .show ()
You can’t perform that action at this time.
0 commit comments