Skip to content

Prepare for rcParams.copy() returning a new RcParams instance in the future #21015

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations/YYYYY-AL.rst
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 7 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]):
Expand Down