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

Skip to content

Commit fc8fb3a

Browse files
committed
MNT: Deprecate rcParams._get("backend")
since 3.10 we have the official API `matplotlib.get_backend (auto_select=False)`. No problems have been reported and matplotlib-inline is using it https://github .com/ipython/matplotlib-inline/pull/38. Therefore, I remove the provisional status from the auto-select flag. Additionally, I deprecate the API rcParams._get('backend'), which the above is replacing. It seems that `rcParams._get("backend")` is not used anywhere publically, but let's still be defensive and deprecate. https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code This is working towards #26406. Follow-up to #29039.
1 parent a5cc230 commit fc8fb3a

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``rcParams._get("backend")``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
``rcParams._get("backend")`` is deprecated. Instead, use the public API
5+
``matplotlib.get_backend(auto_select=False)`` to retrieve the current
6+
backend without triggering backend resolution. This API is available since
7+
Matplotlib 3.10.

lib/matplotlib/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ def _get(self, key):
712712
713713
:meta public:
714714
"""
715+
if key == "backend":
716+
_api.warn_deprecated(
717+
"rcParams._get('backend') is deprecated since Matplotlib 3.11. "
718+
"Use matplotlib.get_backend(auto_select=False) instead, which is "
719+
"available since Matplotlib 3.10.",
720+
)
721+
# TODO: When removing this, also remove the suppression context in
722+
# RcParams.copy
715723
return dict.__getitem__(self, key)
716724

717725
def _update_raw(self, other_params):
@@ -813,8 +821,11 @@ def find_all(self, pattern):
813821
def copy(self):
814822
"""Copy this RcParams instance."""
815823
rccopy = self.__class__()
816-
for k in self: # Skip deprecations and revalidation.
817-
rccopy._set(k, self._get(k))
824+
with _api.suppress_matplotlib_deprecation_warning():
825+
# the suppression context is specifically for _get("backend"). This
826+
# can be removed again, when "backend" is not a valid rcParam anymore.
827+
for k in self: # Skip deprecations and revalidation.
828+
rccopy._set(k, self._get(k))
818829
return rccopy
819830

820831

@@ -1278,23 +1289,14 @@ def get_backend(*, auto_select=True):
12781289
12791290
.. versionadded:: 3.10
12801291
1281-
.. admonition:: Provisional
1282-
1283-
The *auto_select* flag is provisional. It may be changed or removed
1284-
without prior warning.
1285-
12861292
See Also
12871293
--------
12881294
matplotlib.use
12891295
"""
12901296
if auto_select:
12911297
return rcParams['backend']
12921298
else:
1293-
backend = rcParams._get('backend')
1294-
if backend is rcsetup._auto_backend_sentinel:
1295-
return None
1296-
else:
1297-
return backend
1299+
return rcParams._get_backend_or_none()
12981300

12991301

13001302
def interactive(b):

0 commit comments

Comments
 (0)