Skip to content

Cleanup cbook deprecations and layout #24923

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 2 commits into from
Jan 10, 2023
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
15 changes: 15 additions & 0 deletions doc/api/next_api_changes/removals/24923-ES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cbook removals
~~~~~~~~~~~~~~

- ``matplotlib.cbook.MatplotlibDeprecationWarning`` and
``matplotlib.cbook.mplDeprecation`` are removed; use
`matplotlib.MatplotlibDeprecationWarning` instead.
- ``cbook.maxdict``; use the standard library ``functools.lru_cache`` instead.

Groupers from ``get_shared_x_axes`` / ``get_shared_y_axes`` are immutable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Modifications to the Groupers returned by ``get_shared_x_axes`` and
``get_shared_y_axes`` are no longer allowed. Note that previously, calling e.g.
``join()`` would already fail to set up the correct structures for sharing
axes; use `.Axes.sharex` or `.Axes.sharey` instead.
42 changes: 0 additions & 42 deletions lib/matplotlib/cbook/__init__.py → lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@
from matplotlib import _api, _c_internal_utils


@_api.caching_module_getattr
class __getattr__:
# module-level deprecations
MatplotlibDeprecationWarning = _api.deprecated(
"3.6", obj_type="",
alternative="matplotlib.MatplotlibDeprecationWarning")(
property(lambda self: _api.deprecation.MatplotlibDeprecationWarning))
mplDeprecation = _api.deprecated(
"3.6", obj_type="",
alternative="matplotlib.MatplotlibDeprecationWarning")(
property(lambda self: _api.deprecation.MatplotlibDeprecationWarning))


def _get_running_interactive_framework():
"""
Return the interactive framework whose event loop is currently running, if
Expand Down Expand Up @@ -578,27 +565,6 @@ def flatten(seq, scalarp=is_scalar_or_string):
yield from flatten(item, scalarp)


@_api.deprecated("3.6", alternative="functools.lru_cache")
class maxdict(dict):
"""
A dictionary with a maximum size.

Notes
-----
This doesn't override all the relevant methods to constrain the size,
just ``__setitem__``, so use with caution.
"""

def __init__(self, maxsize):
super().__init__()
self.maxsize = maxsize

def __setitem__(self, k, v):
super().__setitem__(k, v)
while len(self) >= self.maxsize:
del self[next(iter(self))]


class Stack:
"""
Stack of elements with a movable cursor.
Expand Down Expand Up @@ -891,25 +857,17 @@ def __init__(self, grouper):
self._grouper = grouper

class _GrouperMethodForwarder:
def __init__(self, deprecated_kw=None):
self._deprecated_kw = deprecated_kw

def __set_name__(self, owner, name):
wrapped = getattr(Grouper, name)
forwarder = functools.wraps(wrapped)(
lambda self, *args, **kwargs: wrapped(
self._grouper, *args, **kwargs))
if self._deprecated_kw:
forwarder = _api.deprecated(**self._deprecated_kw)(forwarder)
setattr(owner, name, forwarder)

__contains__ = _GrouperMethodForwarder()
__iter__ = _GrouperMethodForwarder()
joined = _GrouperMethodForwarder()
get_siblings = _GrouperMethodForwarder()
clean = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
join = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
remove = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))


def simple_linear_interpolation(a, steps):
Expand Down