Skip to content

Deprecate @cbook.deprecated and move internal calls to @_api.deprecated #19151

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 24, 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
4 changes: 2 additions & 2 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def __init__(self, default_font_prop, mathtext_backend=None):
self.fonts['default'] = default_font
self.fonts['regular'] = default_font

pswriter = cbook.deprecated("3.4")(property(lambda self: StringIO()))
pswriter = _api.deprecated("3.4")(property(lambda self: StringIO()))

def _get_font(self, font):
if font in self.fontmap:
Expand Down Expand Up @@ -1549,7 +1549,7 @@ class Glue(Node):
it's easier to stick to what TeX does.)
"""

glue_subtype = cbook.deprecated("3.3")(property(lambda self: "normal"))
glue_subtype = _api.deprecated("3.3")(property(lambda self: "normal"))

@_api.delete_parameter("3.3", "copy")
def __init__(self, glue_type, copy=False):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ class HTMLWriter(FileMovieWriter):
"""Writer for JavaScript-based HTML movies."""

supported_formats = ['png', 'jpeg', 'tiff', 'svg']
args_key = cbook.deprecated("3.3")(property(
args_key = _api.deprecated("3.3")(property(
lambda self: 'animation.html_args'))

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ class FigureManagerBase:
figure.canvas.manager.button_press_handler_id)
"""

statusbar = cbook.deprecated("3.3")(property(lambda self: None))
statusbar = _api.deprecated("3.3")(property(lambda self: None))

def __init__(self, canvas, num):
self.canvas = canvas
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/_backend_pdf_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import functools

import matplotlib as mpl
from matplotlib import _api
from .. import font_manager, ft2font
from ..afm import AFM
from ..backend_bases import RendererBase
Expand All @@ -27,7 +28,7 @@ class CharacterTracker:
def __init__(self):
self.used = {}

@mpl.cbook.deprecated("3.3")
@_api.deprecated("3.3")
@property
def used_characters(self):
d = {}
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def attr(field):


class RendererCairo(RendererBase):
fontweights = cbook.deprecated("3.3")(property(lambda self: {*_f_weights}))
fontangles = cbook.deprecated("3.3")(property(lambda self: {*_f_angles}))
mathtext_parser = cbook.deprecated("3.4")(
fontweights = _api.deprecated("3.3")(property(lambda self: {*_f_weights}))
fontangles = _api.deprecated("3.3")(property(lambda self: {*_f_angles}))
mathtext_parser = _api.deprecated("3.4")(
property(lambda self: MathTextParser('Cairo')))

def __init__(self, dpi):
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 @@ -432,7 +432,7 @@ def resize(self, width, height):


class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):
ctx = cbook.deprecated("3.3")(property(
ctx = _api.deprecated("3.3")(property(
lambda self: self.canvas.get_property("window").cairo_create()))

def __init__(self, canvas, window):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ class PdfPages:
'_info_dict',
'_metadata',
)
metadata = cbook.deprecated('3.3')(property(lambda self: self._metadata))
metadata = _api.deprecated('3.3')(property(lambda self: self._metadata))

def __init__(self, filename, *, keep_empty=True, metadata=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ class RendererPS(_backend_pdf_ps.RendererPDFPSBase):
_afm_font_dir = cbook._get_data_path("fonts/afm")
_use_afm_rc_name = "ps.useafm"

mathtext_parser = cbook.deprecated("3.4")(property(
mathtext_parser = _api.deprecated("3.4")(property(
lambda self: MathTextParser("PS")))
used_characters = cbook.deprecated("3.3")(property(
used_characters = _api.deprecated("3.3")(property(
lambda self: self._character_tracker.used_characters))

def __init__(self, width, height, pswriter, imagedpi=72):
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys

import matplotlib as mpl
from matplotlib import _api


QT_API_PYQT5 = "PyQt5"
Expand Down Expand Up @@ -87,7 +88,7 @@ def _isdeleted(obj): return not shiboken2.isValid(obj)
raise ValueError("Unexpected value for the 'backend.qt5' rcparam")
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName

@mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
@_api.deprecated("3.3", alternative="QtCore.qVersion()")
def is_pyqt5():
return True

Expand Down Expand Up @@ -143,7 +144,7 @@ def _isdeleted(obj): return not shiboken.isValid(obj)
raise ValueError("Unexpected value for the 'backend.qt4' rcparam")
QtWidgets = QtGui

@mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
@_api.deprecated("3.3", alternative="QtCore.qVersion()")
def is_pyqt5():
return False

Expand Down
13 changes: 9 additions & 4 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
import matplotlib
from matplotlib import _api, _c_internal_utils
from matplotlib._api.deprecation import (
deprecated, warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)
warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)


@_api.deprecated("3.4")
def deprecated(*args, **kwargs):
return _api.deprecated(*args, **kwargs)


def _get_running_interactive_framework():
Expand Down Expand Up @@ -287,7 +292,7 @@ def __repr__(self):
return "<an empty list>"


@deprecated("3.3")
@_api.deprecated("3.3")
class IgnoredKeywordWarning(UserWarning):
"""
A class for issuing warnings about keyword arguments that will be ignored
Expand All @@ -296,7 +301,7 @@ class IgnoredKeywordWarning(UserWarning):
pass


@deprecated("3.3", alternative="normalize_kwargs")
@_api.deprecated("3.3", alternative="normalize_kwargs")
def local_over_kwdict(local_var, kwargs, *keys):
"""
Enforces the priority of a local variable over potentially conflicting
Expand Down Expand Up @@ -532,7 +537,7 @@ def flatten(seq, scalarp=is_scalar_or_string):
yield from flatten(item, scalarp)


@deprecated("3.3", alternative="os.path.realpath and os.stat")
@_api.deprecated("3.3", alternative="os.path.realpath and os.stat")
@functools.lru_cache()
def get_realpath_and_stat(path):
realpath = os.path.realpath(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class ContourSet(cm.ScalarMappable, ContourLabeler):
%(contour_set_attributes)s
"""

ax = cbook.deprecated("3.3")(property(lambda self: self.axes))
ax = _api.deprecated("3.3")(property(lambda self: self.axes))

def __init__(self, ax, *args,
levels=None, filled=False, linewidths=None, linestyles=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 @@ -351,7 +351,7 @@ def get_results(self, box, used_characters):
*[c.__name__ for c in _mathtext.Node.__subclasses__()],
"Ship", "Parser",
]:
globals()[_cls_name] = cbook.deprecated("3.4")(
globals()[_cls_name] = _api.deprecated("3.4")(
type(_cls_name, (getattr(_mathtext, _cls_name),), {}))


Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@
import matplotlib
from matplotlib.backend_bases import FigureManagerBase
import matplotlib.pyplot as plt
from matplotlib import _pylab_helpers, cbook
from matplotlib import _api, _pylab_helpers, cbook

matplotlib.use("agg")
align = cbook.deprecated(
align = _api.deprecated(
"3.4", alternative="docutils.parsers.rst.directives.images.Image.align")(
Image.align)

Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ class TexManager:
'computer modern sans serif': ('cmss', r'\usepackage{type1ec}'),
'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')}

cachedir = cbook.deprecated(
cachedir = _api.deprecated(
"3.3", alternative="matplotlib.get_cachedir()")(
property(lambda self: mpl.get_cachedir()))
rgba_arrayd = cbook.deprecated("3.3")(property(lambda self: {}))
rgba_arrayd = _api.deprecated("3.3")(property(lambda self: {}))
_fonts = {} # Only for deprecation period.
serif = cbook.deprecated("3.3")(property(
serif = _api.deprecated("3.3")(property(
lambda self: self._fonts.get("serif", ('cmr', ''))))
sans_serif = cbook.deprecated("3.3")(property(
sans_serif = _api.deprecated("3.3")(property(
lambda self: self._fonts.get("sans-serif", ('cmss', ''))))
cursive = cbook.deprecated("3.3")(property(
cursive = _api.deprecated("3.3")(property(
lambda self:
self._fonts.get("cursive", ('pzc', r'\usepackage{chancery}'))))
monospace = cbook.deprecated("3.3")(property(
monospace = _api.deprecated("3.3")(property(
lambda self: self._fonts.get("monospace", ('cmtt', ''))))

@functools.lru_cache() # Always return the same instance.
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,11 +2118,11 @@ def __init__(self, *args, **kwargs):
"""
if args:
if 'nbins' in kwargs:
cbook.deprecated("3.1",
message='Calling MaxNLocator with positional '
'and keyword parameter *nbins* is '
'considered an error and will fail '
'in future versions of matplotlib.')
_api.deprecated("3.1",
message='Calling MaxNLocator with positional '
'and keyword parameter *nbins* is '
'considered an error and will fail '
'in future versions of matplotlib.')
kwargs['nbins'] = args[0]
if len(args) > 1:
raise ValueError(
Expand Down
38 changes: 19 additions & 19 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AxesWidget(Widget):
If False, the widget does not respond to events.
"""

cids = cbook.deprecated("3.4")(property(lambda self: self._cids))
cids = _api.deprecated("3.4")(property(lambda self: self._cids))

def __init__(self, ax):
self.ax = ax
Expand Down Expand Up @@ -151,9 +151,9 @@ class Button(AxesWidget):
The color of the button when hovering.
"""

cnt = cbook.deprecated("3.4")(property( # Not real, but close enough.
cnt = _api.deprecated("3.4")(property( # Not real, but close enough.
lambda self: len(self._observers.callbacks['clicked'])))
observers = cbook.deprecated("3.4")(property(
observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['clicked']))

def __init__(self, ax, label, image=None,
Expand Down Expand Up @@ -243,9 +243,9 @@ class Slider(AxesWidget):
Slider value.
"""

cnt = cbook.deprecated("3.4")(property( # Not real, but close enough.
cnt = _api.deprecated("3.4")(property( # Not real, but close enough.
lambda self: len(self._observers.callbacks['changed'])))
observers = cbook.deprecated("3.4")(property(
observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['changed']))

def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
Expand Down Expand Up @@ -536,9 +536,9 @@ class CheckButtons(AxesWidget):
each box, but have ``set_visible(False)`` when its box is not checked.
"""

cnt = cbook.deprecated("3.4")(property( # Not real, but close enough.
cnt = _api.deprecated("3.4")(property( # Not real, but close enough.
lambda self: len(self._observers.callbacks['clicked'])))
observers = cbook.deprecated("3.4")(property(
observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['clicked']))

def __init__(self, ax, labels, actives=None):
Expand Down Expand Up @@ -688,13 +688,13 @@ class TextBox(AxesWidget):
The color of the text box when hovering.
"""

params_to_disable = cbook.deprecated("3.3")(property(
params_to_disable = _api.deprecated("3.3")(property(
lambda self: [key for key in mpl.rcParams if 'keymap' in key]))
cnt = cbook.deprecated("3.4")(property( # Not real, but close enough.
cnt = _api.deprecated("3.4")(property( # Not real, but close enough.
lambda self: sum(len(d) for d in self._observers.callbacks.values())))
change_observers = cbook.deprecated("3.4")(property(
change_observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['change']))
submit_observers = cbook.deprecated("3.4")(property(
submit_observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['submit']))

def __init__(self, ax, label, initial='',
Expand Down Expand Up @@ -1005,9 +1005,9 @@ def __init__(self, ax, labels, active=0, activecolor='blue'):

self._observers = cbook.CallbackRegistry()

cnt = cbook.deprecated("3.4")(property( # Not real, but close enough.
cnt = _api.deprecated("3.4")(property( # Not real, but close enough.
lambda self: len(self._observers.callbacks['clicked'])))
observers = cbook.deprecated("3.4")(property(
observers = _api.deprecated("3.4")(property(
lambda self: self._observers.callbacks['clicked']))

def _clicked(self, event):
Expand Down Expand Up @@ -1133,17 +1133,17 @@ def _on_reset(self, event):
event.canvas.draw()
self.targetfig.canvas.draw()

axleft = cbook.deprecated("3.3")(
axleft = _api.deprecated("3.3")(
property(lambda self: self.sliderleft.ax))
axright = cbook.deprecated("3.3")(
axright = _api.deprecated("3.3")(
property(lambda self: self.sliderright.ax))
axbottom = cbook.deprecated("3.3")(
axbottom = _api.deprecated("3.3")(
property(lambda self: self.sliderbottom.ax))
axtop = cbook.deprecated("3.3")(
axtop = _api.deprecated("3.3")(
property(lambda self: self.slidertop.ax))
axwspace = cbook.deprecated("3.3")(
axwspace = _api.deprecated("3.3")(
property(lambda self: self.sliderwspace.ax))
axhspace = cbook.deprecated("3.3")(
axhspace = _api.deprecated("3.3")(
property(lambda self: self.sliderhspace.ax))

@_api.deprecated("3.3")
Expand Down
10 changes: 5 additions & 5 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ def get_zaxis(self):
get_zgridlines = _axis_method_wrapper("zaxis", "get_gridlines")
get_zticklines = _axis_method_wrapper("zaxis", "get_ticklines")

w_xaxis = cbook.deprecated("3.1", alternative="xaxis", pending=True)(
w_xaxis = _api.deprecated("3.1", alternative="xaxis", pending=True)(
property(lambda self: self.xaxis))
w_yaxis = cbook.deprecated("3.1", alternative="yaxis", pending=True)(
w_yaxis = _api.deprecated("3.1", alternative="yaxis", pending=True)(
property(lambda self: self.yaxis))
w_zaxis = cbook.deprecated("3.1", alternative="zaxis", pending=True)(
w_zaxis = _api.deprecated("3.1", alternative="zaxis", pending=True)(
property(lambda self: self.zaxis))

def _get_axis_list(self):
Expand Down Expand Up @@ -406,8 +406,8 @@ def draw(self, renderer):
# the attributes listed below, and they are temporarily attached to
# the _class_ in the `_setattr_cm` call. These can both be removed
# once the deprecation expires
name: cbook.deprecated('3.4', name=name,
alternative=f'self.axes.{name}')(
name: _api.deprecated('3.4', name=name,
alternative=f'self.axes.{name}')(
property(lambda self, _value=getattr(self, name): _value))
for name in ['M', 'vvec', 'eye', 'get_axis_position']
}
Expand Down