diff --git a/lib/matplotlib/_api/deprecation.py b/lib/matplotlib/_api/deprecation.py index 7c3a17965928..1487e30e504d 100644 --- a/lib/matplotlib/_api/deprecation.py +++ b/lib/matplotlib/_api/deprecation.py @@ -273,7 +273,7 @@ def wrapper(*args, **kwargs): class deprecate_privatize_attribute: """ - Helper to deprecate public access to an attribute. + Helper to deprecate public access to an attribute (or method). This helper should only be used at class scope, as follows:: @@ -283,7 +283,8 @@ class Foo: where *all* parameters are forwarded to `deprecated`. This form makes ``attr`` a property which forwards access to ``self._attr`` (same name but with a leading underscore), with a deprecation warning. Note that the - attribute name is derived from *the name this helper is assigned to*. + attribute name is derived from *the name this helper is assigned to*. This + helper also works for deprecating methods. """ def __init__(self, *args, **kwargs): diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 32e069ed69cf..6417d30178c0 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -3264,11 +3264,6 @@ def push_current(self): for ax in self.canvas.figure.axes})) self.set_history_buttons() - @_api.deprecated("3.3", alternative="toolbar.canvas.draw_idle()") - def draw(self): - """Redraw the canvases, update the locators.""" - self._draw() - # Can be removed once Locator.refresh() is removed, and replaced by an # inline call to self.canvas.draw_idle(). def _draw(self): @@ -3287,6 +3282,9 @@ def _draw(self): mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc) self.canvas.draw_idle() + draw = _api.deprecate_privatize_attribute( + "3.3", alternative="toolbar.canvas.draw_idle()") + def _update_view(self): """ Update the viewlim and position from the view and position stack for diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index a8bad1edab5a..2fa598aa2626 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -613,11 +613,6 @@ def update_home_views(self, figure=None): if a not in self.home_views[figure]: self.home_views[figure][a] = a._get_view() - @_api.deprecated("3.3", alternative="self.figure.canvas.draw_idle()") - def refresh_locators(self): - """Redraw the canvases, update the locators.""" - self._refresh_locators() - # Can be removed once Locator.refresh() is removed, and replaced by an # inline call to self.figure.canvas.draw_idle(). def _refresh_locators(self): @@ -640,6 +635,9 @@ def _refresh_locators(self): mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc) self.figure.canvas.draw_idle() + refresh_locators = _api.deprecate_privatize_attribute( + "3.3", alternative="self.figure.canvas.draw_idle()") + def home(self): """Recall the first view and position from the stack.""" self.views[self.figure].home() diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 376d703da13f..667aed880efd 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -501,11 +501,5 @@ def changed(self): self.stale = True update_dict = _api.deprecate_privatize_attribute("3.3") - - @_api.deprecated("3.3") - def add_checker(self, checker): - return self._add_checker(checker) - - @_api.deprecated("3.3") - def check_update(self, checker): - return self._check_update(checker) + add_checker = _api.deprecate_privatize_attribute("3.3") + check_update = _api.deprecate_privatize_attribute("3.3") diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 31d9b6176821..788fdb66b9af 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -546,10 +546,6 @@ def draw_all(self): if self.filled: self._add_solids(X, Y, self._values[:, np.newaxis]) - @_api.deprecated("3.3") - def config_axis(self): - self._config_axis() - def _config_axis(self): """Set up long and short axis.""" ax = self.ax @@ -567,6 +563,8 @@ def _config_axis(self): short_axis.set_ticks([], minor=True) self.stale = True + config_axis = _api.deprecate_privatize_attribute("3.3") + def _get_ticker_locator_formatter(self): """ Return the ``locator`` and ``formatter`` of the colorbar. diff --git a/lib/matplotlib/tests/test_api.py b/lib/matplotlib/tests/test_api.py index 29ca4caf5ca0..43fbb2f2bc8a 100644 --- a/lib/matplotlib/tests/test_api.py +++ b/lib/matplotlib/tests/test_api.py @@ -34,6 +34,19 @@ def f(cls): a.f +def test_deprecate_privatize_attribute(): + class C: + def __init__(self): self._attr = 1 + def _meth(self, arg): pass + attr = _api.deprecate_privatize_attribute("0.0") + meth = _api.deprecate_privatize_attribute("0.0") + + with pytest.warns(_api.MatplotlibDeprecationWarning): + C().attr + with pytest.warns(_api.MatplotlibDeprecationWarning): + C().meth(42) + + def test_delete_parameter(): @_api.delete_parameter("3.0", "foo") def func1(foo=None):