Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57a7f52

Browse files
committed
Deprecate the useless switch_backend_warn parameter to matplotlib.test.
matplotlib.test always calls matplotlib.use() with force set to its default value of True, which means that the warn parameter has no effect. So just don't bother passing it. Also slightly reorder the logic in use() to make this more apparent (I think?).
1 parent dd18211 commit 57a7f52

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
The ``switch_backend_warn`` parameter to ``matplotlib.test`` has no effect and
5+
is deprecated.

lib/matplotlib/__init__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,6 @@ def use(backend, warn=False, force=True):
12621262
If True and not *force*, warn that the call will have no effect if
12631263
this is called after pyplot has been imported and a backend is set up.
12641264
1265-
12661265
force : bool, optional, default: True
12671266
If True, attempt to switch the backend. An ImportError is raised if
12681267
an interactive backend is selected, but another interactive
@@ -1281,20 +1280,17 @@ def use(backend, warn=False, force=True):
12811280
elif 'matplotlib.pyplot' in sys.modules:
12821281
# pyplot has already been imported (which triggered backend selection)
12831282
# and the requested backend is different from the current one.
1284-
1285-
# If we are going to force the switch, never warn, else, if warn
1286-
# is True, then direct users to `plt.switch_backend`
1287-
if (not force) and warn:
1288-
cbook._warn_external(
1289-
"matplotlib.pyplot has already been imported, "
1290-
"this call will have no effect.")
1291-
1292-
# if we are going to force switching the backend, pull in
1293-
# `switch_backend` from pyplot. This will only happen if
1294-
# pyplot is already imported.
12951283
if force:
1284+
# if we are going to force switching the backend, pull in
1285+
# `switch_backend` from pyplot (which is already imported).
12961286
from matplotlib.pyplot import switch_backend
12971287
switch_backend(name)
1288+
elif warn:
1289+
# Only if we are not going to force the switch *and* warn is True,
1290+
# then direct users to `plt.switch_backend`.
1291+
cbook._warn_external(
1292+
"matplotlib.pyplot has already been imported, "
1293+
"this call will have no effect.")
12981294
else:
12991295
# Finally if pyplot is not imported update both rcParams and
13001296
# rcDefaults so restoring the defaults later with rcdefaults
@@ -1385,6 +1381,7 @@ def _init_tests():
13851381
raise
13861382

13871383

1384+
@cbook._delete_parameter("3.2", "switch_backend_warn")
13881385
def test(verbosity=None, coverage=False, switch_backend_warn=True,
13891386
recursionlimit=0, **kwargs):
13901387
"""Run the matplotlib test suite."""
@@ -1426,7 +1423,7 @@ def test(verbosity=None, coverage=False, switch_backend_warn=True,
14261423
retcode = pytest.main(args, **kwargs)
14271424
finally:
14281425
if old_backend.lower() != 'agg':
1429-
use(old_backend, warn=switch_backend_warn)
1426+
use(old_backend)
14301427
if recursionlimit:
14311428
sys.setrecursionlimit(old_recursionlimit)
14321429

tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@
4545

4646
print('Python byte-compilation optimization level:', sys.flags.optimize)
4747

48-
retcode = test(argv=extra_args, switch_backend_warn=False,
49-
recursionlimit=args.recursionlimit)
48+
retcode = test(argv=extra_args, recursionlimit=args.recursionlimit)
5049
sys.exit(retcode)

0 commit comments

Comments
 (0)