Skip to content

Deprecate cbook.warn_deprecated and move internal calls to _api.warn_deprecated #19162

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
Jan 5, 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
15 changes: 12 additions & 3 deletions doc/api/next_api_changes/deprecations/18657-TH.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
``matplotlib.cbook.deprecation`` is deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The module is considered internal and will be removed from the public API.
Deprecation-related functionality is considered internal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The module ``matplotlib.cbook.deprecation`` is considered internal and will be
removed from the public API. This also holds for deprecation-related re-imports
in ``matplotlib.cbook``, i.e. ``matplotlib.cbook.deprecated()``,
``matplotlib.cbook.warn_deprecated()``,
``matplotlib.cbook.MatplotlibDeprecationWarning`` and
``matplotlib.cbook.mplDeprecation``.

If needed, external users may import ``MatplotlibDeprecationWarning`` directly
from the ``matplotlib`` namespace. ``mplDeprecation`` is only an alias of
``MatplotlibDeprecationWarning`` and should not be used anymore.
17 changes: 8 additions & 9 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def get_cachedir():
def get_data_path(*, _from_rc=None):
"""Return the path to Matplotlib data."""
if _from_rc is not None:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.2",
message=("Setting the datapath via matplotlibrc is deprecated "
"%(since)s and will be removed %(removal)s."),
Expand All @@ -495,7 +495,7 @@ def _get_data_path():
if path.is_dir():
return str(path)

cbook.warn_deprecated(
_api.warn_deprecated(
"3.2", message="Matplotlib installs where the data is not in the "
"mpl-data subdirectory of the package are deprecated since %(since)s "
"and support for them will be removed %(removal)s.")
Expand Down Expand Up @@ -617,17 +617,16 @@ def __setitem__(self, key, val):
try:
if key in _deprecated_map:
version, alt_key, alt_val, inverse_alt = _deprecated_map[key]
cbook.warn_deprecated(
_api.warn_deprecated(
version, name=key, obj_type="rcparam", alternative=alt_key)
key = alt_key
val = alt_val(val)
elif key in _deprecated_remain_as_none and val is not None:
version, = _deprecated_remain_as_none[key]
cbook.warn_deprecated(
version, name=key, obj_type="rcparam")
_api.warn_deprecated(version, name=key, obj_type="rcparam")
elif key in _deprecated_ignore_map:
version, alt_key = _deprecated_ignore_map[key]
cbook.warn_deprecated(
_api.warn_deprecated(
version, name=key, obj_type="rcparam", alternative=alt_key)
return
elif key == 'backend':
Expand All @@ -647,13 +646,13 @@ def __setitem__(self, key, val):
def __getitem__(self, key):
if key in _deprecated_map:
version, alt_key, alt_val, inverse_alt = _deprecated_map[key]
cbook.warn_deprecated(
_api.warn_deprecated(
version, name=key, obj_type="rcparam", alternative=alt_key)
return inverse_alt(dict.__getitem__(self, alt_key))

elif key in _deprecated_ignore_map:
version, alt_key = _deprecated_ignore_map[key]
cbook.warn_deprecated(
_api.warn_deprecated(
version, name=key, obj_type="rcparam", alternative=alt_key)
return dict.__getitem__(self, alt_key) if alt_key else None

Expand Down Expand Up @@ -811,7 +810,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
fname, line_no, line.rstrip('\n'), msg)
elif key in _deprecated_ignore_map:
version, alt_key = _deprecated_ignore_map[key]
cbook.warn_deprecated(
_api.warn_deprecated(
version, name=key, alternative=alt_key, obj_type='rcparam',
addendum="Please update your matplotlibrc.")
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ def gen():
except StopIteration:
pass
else:
cbook.warn_deprecated(
_api.warn_deprecated(
"2.2", message="FuncAnimation.save has truncated "
"your animation to 100 frames. In the future, no "
"such truncation will occur; please pass "
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def update(self, props):
with cbook._setattr_cm(self, eventson=False):
for k, v in props.items():
if k != k.lower():
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Case-insensitive properties were "
"deprecated in %(since)s and support will be removed "
"%(removal)s")
Expand Down Expand Up @@ -1156,7 +1156,7 @@ def set(self, **kwargs):
i_other = keys.index(other)
if i_other < i_color:
move_color_to_start = True
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message=f"You have passed the {other!r} kwarg "
"before the 'color' kwarg. Artist.set() currently "
"reorders the properties to apply 'color' first, but "
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,7 @@ def pie(self, x, explode=None, labels=None, colors=None,

if normalize is None:
if sx < 1:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="normalize=None does not normalize "
"if the sum is less than 1 but this behavior "
"is deprecated since %(since)s until %(removal)s. "
Expand Down Expand Up @@ -3062,15 +3062,15 @@ def get_next_color():
return next(color_cycle)

if radius is None:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for passing a radius of None to mean "
"1 is deprecated since %(since)s and will be removed "
"%(removal)s.")
radius = 1

# Starting theta1 is the start fraction of the circle
if startangle is None:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for passing a startangle of None to "
"mean 0 is deprecated since %(since)s and will be removed "
"%(removal)s.")
Expand Down Expand Up @@ -5634,7 +5634,7 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
' X (%d) and/or Y (%d); see help(%s)' % (
C.shape, Nx, Ny, funcname))
if (ncols == Nx or nrows == Ny):
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="shading='flat' when X and Y have the same "
"dimensions as C is deprecated since %(since)s. Either "
"specify the corners of the quadrilaterals with X and Y, "
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ def _update_title_position(self, renderer):
def draw(self, renderer=None, inframe=False):
# docstring inherited
if renderer is None:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for not passing the 'renderer' "
"parameter to Axes.draw() is deprecated since %(since)s and "
"will be removed %(removal)s. Use axes.draw_artist(axes) "
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import uuid

from matplotlib import _api, cbook, docstring
from matplotlib import _api, docstring
import matplotlib.artist as martist
from matplotlib.axes._axes import Axes
from matplotlib.gridspec import GridSpec, SubplotSpec
Expand Down Expand Up @@ -180,7 +180,7 @@ def subplot_class_factory(axes_class=None):
not have to be created for every type of Axes.
"""
if axes_class is None:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for passing None to subplot_class_factory "
"is deprecated since %(since)s; explicitly pass the default Axes "
"class instead. This will become an error %(removal)s.")
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 @@ -416,7 +416,7 @@ def _iter_collection(self, gc, master_transform, all_transforms,
Nurls = len(urls)

if offset_position == "data":
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for offset_position='data' is "
"deprecated since %(since)s and will be removed %(removal)s.")

Expand Down Expand Up @@ -1191,7 +1191,7 @@ def remove_callback(self, func, *args, **kwargs):
pass it to `add_callback` as a `functools.partial` object.
"""
if args or kwargs:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.1", message="In a future version, Timer.remove_callback "
"will not take *args, **kwargs anymore, but remove all "
"callbacks where the callable matches; to keep a specific "
Expand Down Expand Up @@ -1652,7 +1652,7 @@ def wrapper(*args, **kwargs):
for arg in list(kwargs):
if arg in accepted_kwargs:
continue
cbook.warn_deprecated(
_api.warn_deprecated(
'3.3', name=name,
message='%(name)s() got unexpected keyword argument "'
+ arg + '" which is no longer supported as of '
Expand Down Expand Up @@ -1967,7 +1967,7 @@ def enter_notify_event(self, guiEvent=None, xy=None):
else:
x = None
y = None
cbook.warn_deprecated(
_api.warn_deprecated(
'3.0', removal='3.5', name='enter_notify_event',
message='Since %(since)s, %(name)s expects a location but '
'your backend did not pass one. This will become an error '
Expand Down Expand Up @@ -2607,7 +2607,7 @@ def _get_uniform_gridstate(ticks):
for a in canvas.figure.get_axes():
if (event.x is not None and event.y is not None
and a.in_axes(event)): # FIXME: Why only these?
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Toggling axes navigation from the "
"keyboard is deprecated since %(since)s and will be "
"removed %(removal)s.")
Expand All @@ -2620,7 +2620,7 @@ def _get_uniform_gridstate(ticks):
for i, a in enumerate(canvas.figure.get_axes()):
if (event.x is not None and event.y is not None
and a.in_axes(event)): # FIXME: Why only these?
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Toggling axes navigation from the "
"keyboard is deprecated since %(since)s and will be "
"removed %(removal)s.")
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def update_keymap(self, name, key, *args):
self._remove_keys(name)
for key in [key, *args]:
if isinstance(key, str) and validate_stringlist(key) != [key]:
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Passing a list of keys as a single "
"comma-separated string is deprecated since %(since)s and "
"support will be removed %(removal)s; pass keys as a list "
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
linewidths, linestyles, antialiaseds, urls,
offset_position):
if offset_position == "data":
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for offset_position='data' is "
"deprecated since %(since)s and will be removed %(removal)s.")
return self._renderer.draw_path_collection(
Expand Down Expand Up @@ -219,7 +219,7 @@ def get_text_width_height_descent(self, s, prop, ismath):

if ismath in ["TeX", "TeX!"]:
if ismath == "TeX!":
cbook._warn_deprecated(
_api.warn_deprecated(
"3.3", message="Support for ismath='TeX!' is deprecated "
"since %(since)s and will be removed %(removal)s; use "
"ismath='TeX' instead.")
Expand Down Expand Up @@ -573,7 +573,7 @@ def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
quality = pil_kwargs["quality"] = \
dict.__getitem__(mpl.rcParams, "savefig.jpeg_quality")
if quality not in [0, 75, 95]: # default qualities.
cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", name="savefig.jpeg_quality", obj_type="rcParam",
addendum="Set the quality using "
"`pil_kwargs={'quality': ...}`; the future default "
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 @@ -969,7 +969,7 @@ def __init__(self, filename, *, keep_empty=True, metadata=None):
'moddate': 'ModDate',
}.get(key.lower(), key.lower().title())
if canonical != key:
cbook.warn_deprecated(
_api.warn_deprecated(
'3.3', message='Support for setting PDF metadata keys '
'case-insensitively is deprecated since %(since)s and '
'will be removed %(removal)s; '
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .. import cbook
from .. import _api
from .backend_qt5 import (
backend_version, SPECIAL_KEYS,
SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS, # These are deprecated.
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureCanvasQT,
FigureManagerQT, NavigationToolbar2QT, SubplotToolQt, exception_handler)


cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")


@_BackendQT5.export
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt4agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Render to qt from agg
"""

from .. import cbook
from .. import _api
from .backend_qt5agg import (
_BackendQT5Agg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT)


cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")


@_BackendQT5Agg.export
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt4cairo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .. import cbook
from .. import _api
from .backend_qt5cairo import _BackendQT5Cairo, FigureCanvasQTCairo


cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")


@_BackendQT5Cairo.export
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class RendererWx(RendererBase):

def __init__(self, bitmap, dpi):
"""Initialise a wxWindows renderer instance."""
cbook.warn_deprecated(
_api.warn_deprecated(
"2.0", name="wx", obj_type="backend", removal="the future",
alternative="wxagg", addendum="See the Matplotlib usage FAQ for "
"more info on backends.")
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def is_pyqt5():
QT_RC_MAJOR_VERSION = int(QtCore.qVersion().split(".")[0])

if QT_RC_MAJOR_VERSION == 4:
mpl.cbook.warn_deprecated("3.3", name="support for Qt4")
_api.warn_deprecated("3.3", name="support for Qt4")


def _devicePixelRatioF(obj):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/qt_editor/formsubplottool.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from matplotlib import cbook
from matplotlib import _api
from ._formsubplottool import UiSubplotTool


cbook.warn_deprecated(
_api.warn_deprecated(
"3.3", obj_type="module", name=__name__,
alternative="matplotlib.backends.backend_qt5.SubplotToolQt")
__all__ = ["UiSubplotTool"]
15 changes: 10 additions & 5 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@
import matplotlib
from matplotlib import _api, _c_internal_utils
from matplotlib._api.deprecation import (
warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)
MatplotlibDeprecationWarning, mplDeprecation)


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


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


def _get_running_interactive_framework():
"""
Return the interactive framework whose event loop is currently running, if
Expand Down Expand Up @@ -427,9 +432,9 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
if isinstance(fname, os.PathLike):
fname = os.fspath(fname)
if "U" in flag:
warn_deprecated("3.3", message="Passing a flag containing 'U' to "
"to_filehandle() is deprecated since %(since)s and "
"will be removed %(removal)s.")
_api.warn_deprecated(
"3.3", message="Passing a flag containing 'U' to to_filehandle() "
"is deprecated since %(since)s and will be removed %(removal)s.")
flag = flag.replace("U", "")
if isinstance(fname, str):
if fname.endswith('.gz'):
Expand Down Expand Up @@ -491,7 +496,7 @@ def get_sample_data(fname, asfileobj=True, *, np_load=False):
if np_load:
return np.load(path)
else:
warn_deprecated(
_api.warn_deprecated(
"3.3", message="In a future release, get_sample_data "
"will automatically load numpy arrays. Set np_load to "
"True to get the array and suppress this warning. Set "
Expand Down
Loading