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

Skip to content

Commit 7dffd5b

Browse files
tacaswellanntzer
authored andcommitted
MNT: special case the handling of 'backend' in rc_context
If the context block triggers the auto-resolution of the backend keep than information around.
1 parent ce04937 commit 7dffd5b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/matplotlib/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,16 +1292,23 @@ def __init__(self, rc=None, fname=None):
12921292
if rc:
12931293
rcParams.update(rc)
12941294
except Exception:
1295-
# If anything goes wrong, revert to the original rcs.
1296-
dict.update(rcParams, self._orig)
1295+
self.__fallback()
12971296
raise
12981297

1298+
def __fallback(self):
1299+
# If anything goes wrong, revert to the original rcs.
1300+
updated_backend = self._orig['backend']
1301+
dict.update(rcParams, self._orig)
1302+
# except for the backend. If the context block triggered resloving
1303+
# the auto backend resolution keep that value around
1304+
if self._orig['backend'] is rcsetup._auto_backend_sentinel:
1305+
rcParams['backend'] = updated_backend
1306+
12991307
def __enter__(self):
13001308
return self
13011309

13021310
def __exit__(self, exc_type, exc_value, exc_tb):
1303-
# No need to revalidate the original values.
1304-
dict.update(rcParams, self._orig)
1311+
self.__fallback()
13051312

13061313

13071314
def use(arg, warn=True, force=False):

0 commit comments

Comments
 (0)