8000 FIX/API: do not reset backend key in rc_context by tacaswell · Pull Request #23299 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX/API: do not reset backend key in rc_context #23299

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 4 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behavior/23299-TAC.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mpl.rc_context no longer resets the value of :rc:`backend`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`matplotlib.rc_context` incorrectly reset the value of :rc:`backend` if backend
resolution was triggered in the context. This affected only the value. The actual backend
was not changed. Now, `matplotlib.rc_context` does not reset :rc:`backend` anymore.
5 changes: 4 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ def rc_context(rc=None, fname=None):
"""
Return a context manager for temporarily changing rcParams.

The :rc:`backend` will not be reset by the context manager.

Parameters
----------
rc : dict
Expand Down Expand Up @@ -1087,7 +1089,8 @@ def rc_context(rc=None, fname=None):
plt.plot(x, y) # uses 'print.rc'

"""
orig = rcParams.copy()
orig = dict(rcParams.copy())
del orig['backend']
try:
if fname:
rc_file(fname)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ def test_keymaps():
assert isinstance(mpl.rcParams[k], list)


def test_no_backend_reset_rccontext():
assert mpl.rcParams['backend'] != 'module://aardvark'
with mpl.rc_context():
mpl.rcParams['backend'] = 'module://aardvark'
assert mpl.rcParams['backend'] == 'module://aardvark'


def test_rcparams_reset_after_fail():
# There was previously a bug that meant that if rc_context failed and
# raised an exception due to issues in the supplied rc parameters, the
Expand Down
0