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

Skip to content

Commit 969a12c

Browse files
authored
Merge pull request #19653 from anntzer/dpam
deprecate_privatize_attribute also works for privatizing methods.
2 parents d69b42b + 292935d commit 969a12c

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

lib/matplotlib/_api/deprecation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def wrapper(*args, **kwargs):
273273

274274
class deprecate_privatize_attribute:
275275
"""
276-
Helper to deprecate public access to an attribute.
276+
Helper to deprecate public access to an attribute (or method).
277277
278278
This helper should only be used at class scope, as follows::
279279
@@ -283,7 +283,8 @@ class Foo:
283283
where *all* parameters are forwarded to `deprecated`. This form makes
284284
``attr`` a property which forwards access to ``self._attr`` (same name but
285285
with a leading underscore), with a deprecation warning. Note that the
286-
attribute name is derived from *the name this helper is assigned to*.
286+
attribute name is derived from *the name this helper is assigned to*. This
287+
helper also works for deprecating methods.
287288
"""
288289

289290
def __init__(self, *args, **kwargs):

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,11 +3264,6 @@ def push_current(self):
32643264
for ax in self.canvas.figure.axes}))
32653265
self.set_history_buttons()
32663266

3267-
@_api.deprecated("3.3", alternative="toolbar.canvas.draw_idle()")
3268-
def draw(self):
3269-
"""Redraw the canvases, update the locators."""
3270-
self._draw()
3271-
32723267
# Can be removed once Locator.refresh() is removed, and replaced by an
32733268
# inline call to self.canvas.draw_idle().
32743269
def _draw(self):
@@ -3287,6 +3282,9 @@ def _draw(self):
32873282
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
32883283
self.canvas.draw_idle()
32893284

3285+
draw = _api.deprecate_privatize_attribute(
3286+
"3.3", alternative="toolbar.canvas.draw_idle()")
3287+
32903288
def _update_view(self):
32913289
"""
32923290
Update the viewlim and position from the view and position stack for

lib/matplotlib/backend_tools.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,6 @@ def update_home_views(self, figure=None):
613613
if a not in self.home_views[figure]:
614614
self.home_views[figure][a] = a._get_view()
615615

616-
@_api.deprecated("3.3", alternative="self.figure.canvas.draw_idle()")
617-
def refresh_locators(self):
618-
"""Redraw the canvases, update the locators."""
619-
self._refresh_locators()
620-
621616
# Can be removed once Locator.refresh() is removed, and replaced by an
622617
# inline call to self.figure.canvas.draw_idle().
623618
def _refresh_locators(self):
@@ -640,6 +635,9 @@ def _refresh_locators(self):
640635
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
641636
self.figure.canvas.draw_idle()
642637

638+
refresh_locators = _api.deprecate_privatize_attribute(
639+
"3.3", alternative="self.figure.canvas.draw_idle()")
640+
643641
def home(self):
644642
"""Recall the first view and position from the stack."""
645643
self.views[self.figure].home()

lib/matplotlib/cm.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,5 @@ def changed(self):
501501
self.stale = True
502502

503503
update_dict = _api.deprecate_privatize_attribute("3.3")
504-
505-
@_api.deprecated("3.3")
506-
def add_checker(self, checker):
507-
return self._add_checker(checker)
508-
509-
@_api.deprecated("3.3")
510-
def check_update(self, checker):
511-
return self._check_update(checker)
504+
add_checker = _api.deprecate_privatize_attribute("3.3")
505+
check_update = _api.deprecate_privatize_attribute("3.3")

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,6 @@ def draw_all(self):
546546
if self.filled:
547547
self._add_solids(X, Y, self._values[:, np.newaxis])
548548

549-
@_api.deprecated("3.3")
550-
def config_axis(self):
551-
self._config_axis()
552-
553549
def _config_axis(self):
554550
"""Set up long and short axis."""
555551
ax = self.ax
@@ -567,6 +563,8 @@ def _config_axis(self):
567563
short_axis.set_ticks([], minor=True)
568564
self.stale = True
569565

566+
config_axis = _api.deprecate_privatize_attribute("3.3")
567+
570568
def _get_ticker_locator_formatter(self):
571569
"""
572570
Return the ``locator`` and ``formatter`` of the colorbar.

lib/matplotlib/tests/test_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ def f(cls):
3434
a.f
3535

3636

37+
def test_deprecate_privatize_attribute():
38+
class C:
39+
def __init__(self): self._attr = 1
40+
def _meth(self, arg): pass
41+
attr = _api.deprecate_privatize_attribute("0.0")
42+
meth = _api.deprecate_privatize_attribute("0.0")
43+
44+
with pytest.warns(_api.MatplotlibDeprecationWarning):
45+
C().attr
46+
with pytest.warns(_api.MatplotlibDeprecationWarning):
47+
C().meth(42)
48+
49+
3750
def test_delete_parameter():
3851
@_api.delete_parameter("3.0", "foo")
3952
def func1(foo=None):

0 commit comments

Comments
 (0)