From 04fea8c33fad75b204030de1ce6f783f7458233c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:04:26 +0200 Subject: [PATCH] MNT: Deprecate reimported functions in top-level namespace --- .../deprecations/28728-TH.rst | 10 ++++++++++ lib/matplotlib/__init__.py | 20 +++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/28728-TH.rst diff --git a/doc/api/next_api_changes/deprecations/28728-TH.rst b/doc/api/next_api_changes/deprecations/28728-TH.rst new file mode 100644 index 000000000000..56d5a80b439c --- /dev/null +++ b/doc/api/next_api_changes/deprecations/28728-TH.rst @@ -0,0 +1,10 @@ +matplotlib.validate_backend +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +...is deprecated. Please use `matplotlib.rcsetup.validate_backend` instead. + + +matplotlib.sanitize_sequence +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +...is deprecated. Please use `matplotlib.cbook.sanitize_sequence` instead. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 8a77e5601d8c..6b5746ea0f16 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -157,10 +157,8 @@ # cbook must import matplotlib only within function # definitions, so it is safe to import from it here. from . import _api, _version, cbook, _docstring, rcsetup -from matplotlib.cbook import sanitize_sequence from matplotlib._api import MatplotlibDeprecationWarning from matplotlib.rcsetup import cycler # noqa: F401 -from matplotlib.rcsetup import validate_backend _log = logging.getLogger(__name__) @@ -1236,7 +1234,7 @@ def use(backend, *, force=True): matplotlib.pyplot.switch_backend """ - name = validate_backend(backend) + name = rcsetup.validate_backend(backend) # don't (prematurely) resolve the "auto" backend setting if rcParams._get_backend_or_none() == name: # Nothing to do if the requested backend is already set @@ -1340,7 +1338,7 @@ def _replacer(data, value): except Exception: # key does not exist, silently fall back to key pass - return sanitize_sequence(value) + return cbook.sanitize_sequence(value) def _label_from_arg(y, default_name): @@ -1472,8 +1470,8 @@ def inner(ax, *args, data=None, **kwargs): if data is None: return func( ax, - *map(sanitize_sequence, args), - **{k: sanitize_sequence(v) for k, v in kwargs.items()}) + *map(cbook.sanitize_sequence, args), + **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()}) bound = new_sig.bind(ax, *args, **kwargs) auto_label = (bound.arguments.get(label_namer) @@ -1510,6 +1508,16 @@ def inner(ax, *args, data=None, **kwargs): _log.debug('platform is %s', sys.platform) +@_api.deprecated("3.10", alternative="matplotlib.cbook.sanitize_sequence") +def sanitize_sequence(data): + return cbook.sanitize_sequence(data) + + +@_api.deprecated("3.10", alternative="matplotlib.rcsetup.validate_backend") +def validate_backend(s): + return rcsetup.validate_backend(s) + + # workaround: we must defer colormaps import to after loading rcParams, because # colormap creation depends on rcParams from matplotlib.cm import _colormaps as colormaps # noqa: E402