diff --git a/doc/api/next_api_changes/deprecations/YYYYY-AL.rst b/doc/api/next_api_changes/deprecations/YYYYY-AL.rst new file mode 100644 index 000000000000..64453205d252 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/YYYYY-AL.rst @@ -0,0 +1,6 @@ +rcParams.copy() will return a new RcParams instance in the future +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +During the transition period, ``rcParams.copy()`` will emit a +DeprecationWarning. Either use ``dict.copy(rcParams)`` to copy rcParams as +a plain dict, or ``copy.copy(rcParams)`` to copy rcParams as a new RcParams +instance. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index ac84e82c30f6..238447adf6e0 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -708,6 +708,11 @@ def find_all(self, pattern): if pattern_re.search(key)) def copy(self): + _api.warn_deprecated( + "3.6", message="In the future, rcParams.copy() will return a new " + "RcParams instance. During the deprecation period, either use " + "dict.copy(rcParams) to copy rcParams as a plain dict, or " + "copy.copy(rcParams) to copy rcParams as a new RcParams instance.") return {k: dict.__getitem__(self, k) for k in self} @@ -1076,7 +1081,8 @@ def rc_context(rc=None, fname=None): plt.plot(x, y) # uses 'print.rc' """ - orig = rcParams.copy() + with _api.suppress_matplotlib_deprecation_warning(): + orig = rcParams.copy() try: if fname: rc_file(fname) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index b222466dda45..2c1341e50bb4 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -613,7 +613,8 @@ class _xkcd: # work as a non-contextmanager too. def __init__(self, scale, length, randomness): - self._orig = rcParams.copy() + with _api.suppress_matplotlib_deprecation_warning(): + self._orig = rcParams.copy() if rcParams['text.usetex']: raise RuntimeError( diff --git a/lib/matplotlib/tests/test_style.py b/lib/matplotlib/tests/test_style.py index 5ed115abb68f..264581b525dd 100644 --- a/lib/matplotlib/tests/test_style.py +++ b/lib/matplotlib/tests/test_style.py @@ -154,7 +154,7 @@ def test_alias(equiv_styles): rc_dicts = [] for sty in equiv_styles: with style.context(sty): - rc_dicts.append(mpl.rcParams.copy()) + rc_dicts.append(dict.copy(mpl.rcParams)) rc_base = rc_dicts[0] for nm, rc in zip(equiv_styles[1:], rc_dicts[1:]):