Skip to content

Commit

Permalink
Merge pull request matplotlib#28728 from timhoffm/deprecate-reimport
Browse files Browse the repository at this point in the history
MNT: Deprecate reimported functions in top-level namespace
  • Loading branch information
QuLogic authored Aug 16, 2024
2 parents 9fd2ef9 + 04fea8c commit 86f04cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/deprecations/28728-TH.rst
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 14 additions & 6 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -1258,7 +1256,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
Expand Down Expand Up @@ -1362,7 +1360,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):
Expand Down Expand Up @@ -1494,8 +1492,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)
Expand Down Expand Up @@ -1532,6 +1530,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
Expand Down

0 comments on commit 86f04cb

Please sign in to comment.