Skip to content

Move from cbook._deprecate_*() to _api.deprecate_*() #19145

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
Dec 18, 2020
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
2 changes: 1 addition & 1 deletion lib/matplotlib/_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .deprecation import (
deprecated, warn_deprecated,
rename_parameter, delete_parameter, make_keyword_only,
_deprecate_method_override, _deprecate_privatize_attribute,
deprecate_method_override, deprecate_privatize_attribute,
suppress_matplotlib_deprecation_warning,
MatplotlibDeprecationWarning)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def wrapper(*args, **kwargs):
return deprecate


class _deprecate_privatize_attribute:
class deprecate_privatize_attribute:
"""
Helper to deprecate public access to an attribute.

Expand Down Expand Up @@ -473,7 +473,7 @@ def wrapper(*args, **kwargs):
return wrapper


def _deprecate_method_override(method, obj, *, allow_empty=False, **kwargs):
def deprecate_method_override(method, obj, *, allow_empty=False, **kwargs):
"""
Return ``obj.method`` with a deprecation if it was overridden, else None.

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_results(self, box):
result = self.mathtext_backend.get_results(
box, self.get_used_characters())
if self.destroy != TruetypeFonts.destroy.__get__(self):
destroy = cbook._deprecate_method_override(
destroy = _api.deprecate_method_override(
__class__.destroy, self, since="3.4")
if destroy:
destroy()
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class MovieWriter(AbstractMovieWriter):
# stored. Third-party writers cannot meaningfully set these as they cannot
# extend rcParams with new keys.

exec_key = cbook._deprecate_privatize_attribute("3.3")
args_key = cbook._deprecate_privatize_attribute("3.3")
exec_key = _api.deprecate_privatize_attribute("3.3")
args_key = _api.deprecate_privatize_attribute("3.3")

# Pipe-based writers only support RGBA, but file-based ones support more
# formats.
Expand Down Expand Up @@ -339,7 +339,7 @@ def _run(self):

def finish(self):
"""Finish any processing for writing the movie."""
overridden_cleanup = cbook._deprecate_method_override(
overridden_cleanup = _api.deprecate_method_override(
__class__.cleanup, self, since="3.4", alternative="finish()")
if overridden_cleanup is not None:
overridden_cleanup()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __init__(self, axes, loc, label=None,
("_get_gridline", "gridline"),
("_get_text1", "label1"),
("_get_text2", "label2")]:
overridden_method = cbook._deprecate_method_override(
overridden_method = _api.deprecate_method_override(
getattr(__class__, meth), self, since="3.3", message="Relying "
f"on {meth} to initialize Tick.{attr} is deprecated since "
f"%(since)s and will not work %(removal)s; please directly "
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,7 +2876,7 @@ def __init__(self, canvas):
# This cursor will be set after the initial draw.
self._lastCursor = cursors.POINTER

init = cbook._deprecate_method_override(
init = _api.deprecate_method_override(
__class__._init_toolbar, self, allow_empty=True, since="3.3",
addendum="Please fully initialize the toolbar in your subclass' "
"__init__; a fully empty _init_toolbar implementation may be kept "
Expand Down Expand Up @@ -3093,7 +3093,7 @@ def press_pan(self, event):
id_drag = self.canvas.mpl_connect("motion_notify_event", self.drag_pan)
self._pan_info = self._PanInfo(
button=event.button, axes=axes, cid=id_drag)
press = cbook._deprecate_method_override(
press = _api.deprecate_method_override(
__class__.press, self, since="3.3", message="Calling an "
"overridden press() at pan start is deprecated since %(since)s "
"and will be removed %(removal)s; override press_pan() instead.")
Expand All @@ -3117,7 +3117,7 @@ def release_pan(self, event):
'motion_notify_event', self.mouse_move)
for ax in self._pan_info.axes:
ax.end_pan()
release = cbook._deprecate_method_override(
release = _api.deprecate_method_override(
__class__.press, self, since="3.3", message="Calling an "
"overridden release() at pan stop is deprecated since %(since)s "
"and will be removed %(removal)s; override release_pan() instead.")
Expand Down Expand Up @@ -3157,7 +3157,7 @@ def press_zoom(self, event):
self._zoom_info = self._ZoomInfo(
direction="in" if event.button == 1 else "out",
start_xy=(event.x, event.y), axes=axes, cid=id_zoom)
press = cbook._deprecate_method_override(
press = _api.deprecate_method_override(
__class__.press, self, since="3.3", message="Calling an "
"overridden press() at zoom start is deprecated since %(since)s "
"and will be removed %(removal)s; override press_zoom() instead.")
Expand Down Expand Up @@ -3193,7 +3193,7 @@ def release_zoom(self, event):
or (abs(event.y - start_y) < 5 and event.key != "x")):
self._draw()
self._zoom_info = None
release = cbook._deprecate_method_override(
release = _api.deprecate_method_override(
__class__.press, self, since="3.3", message="Calling an "
"overridden release() at zoom stop is deprecated since "
"%(since)s and will be removed %(removal)s; override "
Expand All @@ -3217,7 +3217,7 @@ def release_zoom(self, event):
self._zoom_info = None
self.push_current()

release = cbook._deprecate_method_override(
release = _api.deprecate_method_override(
__class__.release, self, since="3.3", message="Calling an "
"overridden release() at zoom stop is deprecated since %(since)s "
"and will be removed %(removal)s; override release_zoom() "
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, figure):
self.set_double_buffered(True)
self.set_can_focus(True)

renderer_init = cbook._deprecate_method_override(
renderer_init = _api.deprecate_method_override(
__class__._renderer_init, self, allow_empty=True, since="3.3",
addendum="Please initialize the renderer, if needed, in the "
"subclass' __init__; a fully empty _renderer_init implementation "
Expand Down
14 changes: 7 additions & 7 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,13 @@ def __init__(self, canvas, coordinates=True):
# and/or dc.GetContentScaleFactor()
self._retinaFix = 'wxMac' in wx.PlatformInfo

prevZoomRect = cbook._deprecate_privatize_attribute("3.3")
retinaFix = cbook._deprecate_privatize_attribute("3.3")
savedRetinaImage = cbook._deprecate_privatize_attribute("3.3")
wxoverlay = cbook._deprecate_privatize_attribute("3.3")
zoomAxes = cbook._deprecate_privatize_attribute("3.3")
zoomStartX = cbook._deprecate_privatize_attribute("3.3")
zoomStartY = cbook._deprecate_privatize_attribute("3.3")
prevZoomRect = _api.deprecate_privatize_attribute("3.3")
retinaFix = _api.deprecate_privatize_attribute("3.3")
savedRetinaImage = _api.deprecate_privatize_attribute("3.3")
wxoverlay = _api.deprecate_privatize_attribute("3.3")
zoomAxes = _api.deprecate_privatize_attribute("3.3")
zoomStartX = _api.deprecate_privatize_attribute("3.3")
zoomStartY = _api.deprecate_privatize_attribute("3.3")

@staticmethod
def _icon(name):
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
from matplotlib._api import (
warn_external as _warn_external, classproperty as _classproperty)
from matplotlib._api.deprecation import (
deprecated, warn_deprecated,
_deprecate_method_override, _deprecate_privatize_attribute,
MatplotlibDeprecationWarning, mplDeprecation)
deprecated, warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)


def _get_running_interactive_framework():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def changed(self):
self._update_dict[key] = True
self.stale = True

update_dict = cbook._deprecate_privatize_attribute("3.3")
update_dict = _api.deprecate_privatize_attribute("3.3")

@_api.deprecated("3.3")
def add_checker(self, checker):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def _check_unsampled_image(self):
"""Return False. Do not use unsampled image."""
return False

is_grayscale = cbook._deprecate_privatize_attribute("3.3")
is_grayscale = _api.deprecate_privatize_attribute("3.3")

def make_image(self, renderer, magnification=1.0, unsampled=False):
# docstring inherited
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def __init__(self, ax,
if A is not None:
self.set_data(x, y, A)

is_grayscale = cbook._deprecate_privatize_attribute("3.3")
is_grayscale = _api.deprecate_privatize_attribute("3.3")

def make_image(self, renderer, magnification=1.0, unsampled=False):
# docstring inherited
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import numpy as np

from matplotlib import _api, cbook, docstring, rcParams
from matplotlib import _api, docstring, rcParams
import matplotlib.artist as martist
import matplotlib.path as mpath
import matplotlib.text as mtext
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def __init__(self, ref_artist, use_blit=False):

if not ref_artist.pickable():
ref_artist.set_picker(True)
overridden_picker = cbook._deprecate_method_override(
overridden_picker = _api.deprecate_method_override(
__class__.artist_picker, self, since="3.3",
addendum="Directly set the artist's picker if desired.")
if overridden_picker is not None:
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def __init__(self, patch, ox, oy, props=None, **kwargs):
self._shadow_transform = transforms.Affine2D()
self._update()

props = cbook._deprecate_privatize_attribute("3.3")
props = _api.deprecate_privatize_attribute("3.3")

def _update(self):
self.update_from(self.patch)
Expand Down Expand Up @@ -2006,7 +2006,7 @@ def transmute(self, x0, y0, width, height, mutation_size):
# This can go away once the deprecation period elapses, leaving _Base
# as a fully abstract base class just providing docstrings, no logic.
def __init_subclass__(cls):
transmute = cbook._deprecate_method_override(
transmute = _api.deprecate_method_override(
__class__.transmute, cls, since="3.4")
if transmute:
cls.__call__ = transmute
Expand Down
6 changes: 3 additions & 3 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

import matplotlib as mpl
from matplotlib import _api, cbook
from matplotlib import _api
from matplotlib.gridspec import SubplotSpec

from .axes_divider import Size, SubplotDivider, Divider
Expand Down Expand Up @@ -40,9 +40,9 @@ def colorbar(self, mappable, *, ticks=None, **kwargs):
self._config_axes()
return cb

cbid = cbook._deprecate_privatize_attribute(
cbid = _api.deprecate_privatize_attribute(
"3.3", alternative="mappable.colorbar_cid")
locator = cbook._deprecate_privatize_attribute(
locator = _api.deprecate_privatize_attribute(
"3.3", alternative=".colorbar().locator")

def _config_axes(self):
Expand Down