Skip to content

MNT: Deprecate reimported functions in top-level namespace #28728

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

Merged
merged 1 commit into from
Aug 16, 2024
Merged
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
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 @@ -1236,7 +1234,7 @@
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 @@ -1340,7 +1338,7 @@
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 @@ -1472,8 +1470,8 @@
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 @@ -1510,6 +1508,16 @@
_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)

Check warning on line 1513 in lib/matplotlib/__init__.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/__init__.py#L1513

Added line #L1513 was not covered by tests


@_api.deprecated("3.10", alternative="matplotlib.rcsetup.validate_backend")
def validate_backend(s):
return rcsetup.validate_backend(s)

Check warning on line 1518 in lib/matplotlib/__init__.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/__init__.py#L1518

Added line #L1518 was not covered by tests


# 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
Loading