@@ -712,6 +712,35 @@ def _get(self, key):
712
712
"""
713
713
return dict .__getitem__ (self , key )
714
714
715
+ def _update_raw (self , other_params ):
716
+ """
717
+ Directly update the data from *other_params*, bypassing deprecation,
718
+ backend and validation logic on both sides.
719
+
720
+ This ``rcParams._update_raw(params)`` replaces the previous pattern
721
+ ``dict.update(rcParams, params)``.
722
+
723
+ Parameters
724
+ ----------
725
+ other_params : dict or `.RcParams`
726
+ The input mapping from which to update.
727
+ """
728
+ if isinstance (other_params , RcParams ):
729
+ other_params = dict .items (other_params )
730
+ dict .update (self , other_params )
731
+
732
+ def _ensure_has_backend (self ):
733
+ """
734
+ Ensure that a "backend" entry exists.
735
+
736
+ Normally, the default matplotlibrc file contains *no* entry for "backend" (the
737
+ corresponding line starts with ##, not #; we fill in _auto_backend_sentinel
738
+ in that case. However, packagers can set a different default backend
739
+ (resulting in a normal `#backend: foo` line) in which case we should *not*
740
+ fill in _auto_backend_sentinel.
741
+ """
742
+ dict .setdefault (self , "backend" , rcsetup ._auto_backend_sentinel )
743
+
715
744
def __setitem__ (self , key , val ):
716
745
try :
717
746
if key in _deprecated_map :
@@ -961,24 +990,17 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
961
990
return config
962
991
963
992
964
- # When constructing the global instances, we need to perform certain updates
965
- # by explicitly calling the superclass (dict.update, dict.items) to avoid
966
- # triggering resolution of _auto_backend_sentinel.
967
993
rcParamsDefault = _rc_params_in_file (
968
994
cbook ._get_data_path ("matplotlibrc" ),
969
995
# Strip leading comment.
970
996
transform = lambda line : line [1 :] if line .startswith ("#" ) else line ,
971
997
fail_on_error = True )
972
- dict .update (rcParamsDefault , rcsetup ._hardcoded_defaults )
973
- # Normally, the default matplotlibrc file contains *no* entry for backend (the
974
- # corresponding line starts with ##, not #; we fill on _auto_backend_sentinel
975
- # in that case. However, packagers can set a different default backend
976
- # (resulting in a normal `#backend: foo` line) in which case we should *not*
977
- # fill in _auto_backend_sentinel.
978
- dict .setdefault (rcParamsDefault , "backend" , rcsetup ._auto_backend_sentinel )
998
+ rcParamsDefault ._update_raw (rcsetup ._hardcoded_defaults )
999
+ rcParamsDefault ._ensure_has_backend ()
1000
+
979
1001
rcParams = RcParams () # The global instance.
980
- dict . update ( rcParams , dict . items (rcParamsDefault ) )
981
- dict . update ( rcParams , _rc_params_in_file (matplotlib_fname ()))
1002
+ rcParams . _update_raw (rcParamsDefault )
1003
+ rcParams . _update_raw ( _rc_params_in_file (matplotlib_fname ()))
982
1004
rcParamsOrig = rcParams .copy ()
983
1005
with _api .suppress_matplotlib_deprecation_warning ():
984
1006
# This also checks that all rcParams are indeed listed in the template.
@@ -1190,7 +1212,7 @@ def rc_context(rc=None, fname=None):
1190
1212
rcParams .update (rc )
1191
1213
yield
1192
1214
finally :
1193
- dict . update ( rcParams , orig ) # Revert to the original rcs.
1215
+ rcParams . _update_raw ( orig ) # Revert to the original rcs.
1194
1216
1195
1217
1196
1218
def use (backend , * , force = True ):
0 commit comments