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

Skip to content

Deprecate the useless switch_backend_warn parameter to matplotlib.test. #13935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2019-04-12-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

The ``switch_backend_warn`` parameter to ``matplotlib.test`` has no effect and
is deprecated.
23 changes: 10 additions & 13 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,6 @@ def use(backend, warn=False, force=True):
If True and not *force*, warn that the call will have no effect if
this is called after pyplot has been imported and a backend is set up.


force : bool, optional, default: True
If True, attempt to switch the backend. An ImportError is raised if
an interactive backend is selected, but another interactive
Expand All @@ -1281,20 +1280,17 @@ def use(backend, warn=False, force=True):
elif 'matplotlib.pyplot' in sys.modules:
# pyplot has already been imported (which triggered backend selection)
# and the requested backend is different from the current one.

# If we are going to force the switch, never warn, else, if warn
# is True, then direct users to `plt.switch_backend`
if (not force) and warn:
cbook._warn_external(
"matplotlib.pyplot has already been imported, "
"this call will have no effect.")

# if we are going to force switching the backend, pull in
# `switch_backend` from pyplot. This will only happen if
# pyplot is already imported.
if force:
# if we are going to force switching the backend, pull in
# `switch_backend` from pyplot (which is already imported).
from matplotlib.pyplot import switch_backend
switch_backend(name)
elif warn:
# Only if we are not going to force the switch *and* warn is True,
# then direct users to `plt.switch_backend`.
cbook._warn_external(
"matplotlib.pyplot has already been imported, "
"this call will have no effect.")
else:
# Finally if pyplot is not imported update both rcParams and
# rcDefaults so restoring the defaults later with rcdefaults
Expand Down Expand Up @@ -1385,6 +1381,7 @@ def _init_tests():
raise


@cbook._delete_parameter("3.2", "switch_backend_warn")
def test(verbosity=None, coverage=False, switch_backend_warn=True,
recursionlimit=0, **kwargs):
"""Run the matplotlib test suite."""
Expand Down Expand Up @@ -1426,7 +1423,7 @@ def test(verbosity=None, coverage=False, switch_backend_warn=True,
retcode = pytest.main(args, **kwargs)
finally:
if old_backend.lower() != 'agg':
use(old_backend, warn=switch_backend_warn)
use(old_backend)
if recursionlimit:
sys.setrecursionlimit(old_recursionlimit)

Expand Down
3 changes: 1 addition & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@

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

retcode = test(argv=extra_args, switch_backend_warn=False,
recursionlimit=args.recursionlimit)
retcode = test(argv=extra_args, recursionlimit=args.recursionlimit)
sys.exit(retcode)