Thanks to visit codestin.com
Credit goes to github.com

Skip to content

deprecate_privatize_attribute also works for privatizing methods. #19653

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
Mar 9, 2021
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
5 changes: 3 additions & 2 deletions lib/matplotlib/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
6 changes: 2 additions & 4 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down