Skip to content
Draft
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/deprecations/30963-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
``rcParams._get("backend")``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``rcParams._get("backend")`` is deprecated. Instead, use the public API
``matplotlib.get_backend(auto_select=False)`` to retrieve the current
backend without triggering backend resolution. This API is available since
Matplotlib 3.10.
26 changes: 14 additions & 12 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ def _get(self, key):

:meta public:
"""
if key == "backend":
_api.warn_deprecated(
"rcParams._get('backend') is deprecated since Matplotlib 3.11. "
"Use matplotlib.get_backend(auto_select=False) instead, which is "
"available since Matplotlib 3.10.",
)
Comment on lines +716 to +720
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first arg is since, not the full message.

Suggested change
_api.warn_deprecated(
"rcParams._get('backend') is deprecated since Matplotlib 3.11. "
"Use matplotlib.get_backend(auto_select=False) instead, which is "
"available since Matplotlib 3.10.",
)
_api.warn_deprecated(
"3.11",
name="rcParams._get('backend')",
addendum="Use matplotlib.get_backend(auto_select=False) instead, which is "
"available since Matplotlib 3.10.",
)

# TODO: When removing this, also remove the suppression context in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "this"? The comment is in an odd spot to decide if it's the if, the warning, or the whole method.

# RcParams.copy
return dict.__getitem__(self, key)

def _update_raw(self, other_params):
Expand Down Expand Up @@ -813,8 +821,11 @@ def find_all(self, pattern):
def copy(self):
"""Copy this RcParams instance."""
rccopy = self.__class__()
for k in self: # Skip deprecations and revalidation.
rccopy._set(k, self._get(k))
with _api.suppress_matplotlib_deprecation_warning():
# the suppression context is specifically for _get("backend"). This
# can be removed again, when "backend" is not a valid rcParam anymore.
for k in self: # Skip deprecations and revalidation.
rccopy._set(k, self._get(k))
return rccopy


Expand Down Expand Up @@ -1278,23 +1289,14 @@ def get_backend(*, auto_select=True):

.. versionadded:: 3.10

.. admonition:: Provisional

The *auto_select* flag is provisional. It may be changed or removed
without prior warning.

See Also
--------
matplotlib.use
"""
if auto_select:
return rcParams['backend']
else:
backend = rcParams._get('backend')
if backend is rcsetup._auto_backend_sentinel:
return None
else:
return backend
return rcParams._get_backend_or_none()


def interactive(b):
Expand Down
Loading