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

Skip to content

Commit ecc851c

Browse files
committed
Deprecate cbook.warn_deprecated and move internal calls to _api.warn_deprecated
1 parent 0520035 commit ecc851c

37 files changed

+115
-101
lines changed
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
``matplotlib.cbook.deprecation`` is deprecated
2-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3-
The module is considered internal and will be removed from the public API.
1+
Deprecation-related functionality is considered internal
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The module ``matplotlib.cbook.deprecation`` is considered internal and will be
4+
removed from the public API. This also holds for deprecation-related re-imports
5+
in ``matplotlib.cbook``, i.e. ``matplotlib.cbook.deprecated()``,
6+
``matplotlib.cbook.warn_deprecated()``,
7+
``matplotlib.cbook.MatplotlibDeprecationWarning`` and
8+
``matplotlib.cbook.mplDeprecation``.
9+
10+
If needed, external users may import ``MatplotlibDeprecationWarning`` directly
11+
from the ``matplotlib`` namespace. ``mplDeprecation`` is only an alias of
12+
``MatplotlibDeprecationWarning`` and should not be used anymore.

lib/matplotlib/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def get_cachedir():
472472
def get_data_path(*, _from_rc=None):
473473
"""Return the path to Matplotlib data."""
474474
if _from_rc is not None:
475-
cbook.warn_deprecated(
475+
_api.warn_deprecated(
476476
"3.2",
477477
message=("Setting the datapath via matplotlibrc is deprecated "
478478
"%(since)s and will be removed %(removal)s."),
@@ -495,7 +495,7 @@ def _get_data_path():
495495
if path.is_dir():
496496
return str(path)
497497

498-
cbook.warn_deprecated(
498+
_api.warn_deprecated(
499499
"3.2", message="Matplotlib installs where the data is not in the "
500500
"mpl-data subdirectory of the package are deprecated since %(since)s "
501501
"and support for them will be removed %(removal)s.")
@@ -617,17 +617,17 @@ def __setitem__(self, key, val):
617617
try:
618618
if key in _deprecated_map:
619619
version, alt_key, alt_val, inverse_alt = _deprecated_map[key]
620-
cbook.warn_deprecated(
620+
_api.warn_deprecated(
621621
version, name=key, obj_type="rcparam", alternative=alt_key)
622622
key = alt_key
623623
val = alt_val(val)
624624
elif key in _deprecated_remain_as_none and val is not None:
625625
version, = _deprecated_remain_as_none[key]
626-
cbook.warn_deprecated(
626+
_api.warn_deprecated(
627627
version, name=key, obj_type="rcparam")
628628
elif key in _deprecated_ignore_map:
629629
version, alt_key = _deprecated_ignore_map[key]
630-
cbook.warn_deprecated(
630+
_api.warn_deprecated(
631631
version, name=key, obj_type="rcparam", alternative=alt_key)
632632
return
633633
elif key == 'backend':
@@ -647,13 +647,13 @@ def __setitem__(self, key, val):
647647
def __getitem__(self, key):
648648
if key in _deprecated_map:
649649
version, alt_key, alt_val, inverse_alt = _deprecated_map[key]
650-
cbook.warn_deprecated(
650+
_api.warn_deprecated(
651651
version, name=key, obj_type="rcparam", alternative=alt_key)
652652
return inverse_alt(dict.__getitem__(self, alt_key))
653653

654654
elif key in _deprecated_ignore_map:
655655
version, alt_key = _deprecated_ignore_map[key]
656-
cbook.warn_deprecated(
656+
_api.warn_deprecated(
657657
version, name=key, obj_type="rcparam", alternative=alt_key)
658658
return dict.__getitem__(self, alt_key) if alt_key else None
659659

@@ -811,7 +811,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
811811
fname, line_no, line.rstrip('\n'), msg)
812812
elif key in _deprecated_ignore_map:
813813
version, alt_key = _deprecated_ignore_map[key]
814-
cbook.warn_deprecated(
814+
_api.warn_deprecated(
815815
version, name=key, alternative=alt_key, obj_type='rcparam',
816816
addendum="Please update your matplotlibrc.")
817817
else:

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ def gen():
17191719
except StopIteration:
17201720
pass
17211721
else:
1722-
cbook.warn_deprecated(
1722+
_api.warn_deprecated(
17231723
"2.2", message="FuncAnimation.save has truncated "
17241724
"your animation to 100 frames. In the future, no "
17251725
"such truncation will occur; please pass "

lib/matplotlib/artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def update(self, props):
10361036
with cbook._setattr_cm(self, eventson=False):
10371037
for k, v in props.items():
10381038
if k != k.lower():
1039-
cbook.warn_deprecated(
1039+
_api.warn_deprecated(
10401040
"3.3", message="Case-insensitive properties were "
10411041
"deprecated in %(since)s and support will be removed "
10421042
"%(removal)s")
@@ -1156,7 +1156,7 @@ def set(self, **kwargs):
11561156
i_other = keys.index(other)
11571157
if i_other < i_color:
11581158
move_color_to_start = True
1159-
cbook.warn_deprecated(
1159+
_api.warn_deprecated(
11601160
"3.3", message=f"You have passed the {other!r} kwarg "
11611161
"before the 'color' kwarg. Artist.set() currently "
11621162
"reorders the properties to apply 'color' first, but "

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
30323032

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

30643064
if radius is None:
3065-
cbook.warn_deprecated(
3065+
_api.warn_deprecated(
30663066
"3.3", message="Support for passing a radius of None to mean "
30673067
"1 is deprecated since %(since)s and will be removed "
30683068
"%(removal)s.")
30693069
radius = 1
30703070

30713071
# Starting theta1 is the start fraction of the circle
30723072
if startangle is None:
3073-
cbook.warn_deprecated(
3073+
_api.warn_deprecated(
30743074
"3.3", message="Support for passing a startangle of None to "
30753075
"mean 0 is deprecated since %(since)s and will be removed "
30763076
"%(removal)s.")
@@ -5634,7 +5634,7 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
56345634
' X (%d) and/or Y (%d); see help(%s)' % (
56355635
C.shape, Nx, Ny, funcname))
56365636
if (ncols == Nx or nrows == Ny):
5637-
cbook.warn_deprecated(
5637+
_api.warn_deprecated(
56385638
"3.3", message="shading='flat' when X and Y have the same "
56395639
"dimensions as C is deprecated since %(since)s. Either "
56405640
"specify the corners of the quadrilaterals with X and Y, "

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ def _update_title_position(self, renderer):
27722772
def draw(self, renderer=None, inframe=False):
27732773
# docstring inherited
27742774
if renderer is None:
2775-
cbook.warn_deprecated(
2775+
_api.warn_deprecated(
27762776
"3.3", message="Support for not passing the 'renderer' "
27772777
"parameter to Axes.draw() is deprecated since %(since)s and "
27782778
"will be removed %(removal)s. Use axes.draw_artist(axes) "

lib/matplotlib/axes/_subplots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
22
import uuid
33

4-
from matplotlib import _api, cbook, docstring
4+
from matplotlib import _api, docstring
55
import matplotlib.artist as martist
66
from matplotlib.axes._axes import Axes
77
from matplotlib.gridspec import GridSpec, SubplotSpec
@@ -180,7 +180,7 @@ def subplot_class_factory(axes_class=None):
180180
not have to be created for every type of Axes.
181181
"""
182182
if axes_class is None:
183-
cbook.warn_deprecated(
183+
_api.warn_deprecated(
184184
"3.3", message="Support for passing None to subplot_class_factory "
185185
"is deprecated since %(since)s; explicitly pass the default Axes "
186186
"class instead. This will become an error %(removal)s.")

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _iter_collection(self, gc, master_transform, all_transforms,
416416
Nurls = len(urls)
417417

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

@@ -1191,7 +1191,7 @@ def remove_callback(self, func, *args, **kwargs):
11911191
pass it to `add_callback` as a `functools.partial` object.
11921192
"""
11931193
if args or kwargs:
1194-
cbook.warn_deprecated(
1194+
_api.warn_deprecated(
11951195
"3.1", message="In a future version, Timer.remove_callback "
11961196
"will not take *args, **kwargs anymore, but remove all "
11971197
"callbacks where the callable matches; to keep a specific "
@@ -1652,7 +1652,7 @@ def wrapper(*args, **kwargs):
16521652
for arg in list(kwargs):
16531653
if arg in accepted_kwargs:
16541654
continue
1655-
cbook.warn_deprecated(
1655+
_api.warn_deprecated(
16561656
'3.3', name=name,
16571657
message='%(name)s() got unexpected keyword argument "'
16581658
+ arg + '" which is no longer supported as of '
@@ -1967,7 +1967,7 @@ def enter_notify_event(self, guiEvent=None, xy=None):
19671967
else:
19681968
x = None
19691969
y = None
1970-
cbook.warn_deprecated(
1970+
_api.warn_deprecated(
19711971
'3.0', removal='3.5', name='enter_notify_event',
19721972
message='Since %(since)s, %(name)s expects a location but '
19731973
'your backend did not pass one. This will become an error '
@@ -2607,7 +2607,7 @@ def _get_uniform_gridstate(ticks):
26072607
for a in canvas.figure.get_axes():
26082608
if (event.x is not None and event.y is not None
26092609
and a.in_axes(event)): # FIXME: Why only these?
2610-
cbook.warn_deprecated(
2610+
_api.warn_deprecated(
26112611
"3.3", message="Toggling axes navigation from the "
26122612
"keyboard is deprecated since %(since)s and will be "
26132613
"removed %(removal)s.")
@@ -2620,7 +2620,7 @@ def _get_uniform_gridstate(ticks):
26202620
for i, a in enumerate(canvas.figure.get_axes()):
26212621
if (event.x is not None and event.y is not None
26222622
and a.in_axes(event)): # FIXME: Why only these?
2623-
cbook.warn_deprecated(
2623+
_api.warn_deprecated(
26242624
"3.3", message="Toggling axes navigation from the "
26252625
"keyboard is deprecated since %(since)s and will be "
26262626
"removed %(removal)s.")

lib/matplotlib/backend_managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def update_keymap(self, name, key, *args):
199199
self._remove_keys(name)
200200
for key in [key, *args]:
201201
if isinstance(key, str) and validate_stringlist(key) != [key]:
202-
cbook.warn_deprecated(
202+
_api.warn_deprecated(
203203
"3.3", message="Passing a list of keys as a single "
204204
"comma-separated string is deprecated since %(since)s and "
205205
"support will be removed %(removal)s; pass keys as a list "

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
168168
linewidths, linestyles, antialiaseds, urls,
169169
offset_position):
170170
if offset_position == "data":
171-
cbook.warn_deprecated(
171+
_api.warn_deprecated(
172172
"3.3", message="Support for offset_position='data' is "
173173
"deprecated since %(since)s and will be removed %(removal)s.")
174174
return self._renderer.draw_path_collection(
@@ -219,7 +219,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
219219

220220
if ismath in ["TeX", "TeX!"]:
221221
if ismath == "TeX!":
222-
cbook._warn_deprecated(
222+
_api.warn_deprecated(
223223
"3.3", message="Support for ismath='TeX!' is deprecated "
224224
"since %(since)s and will be removed %(removal)s; use "
225225
"ismath='TeX' instead.")
@@ -573,7 +573,7 @@ def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
573573
quality = pil_kwargs["quality"] = \
574574
dict.__getitem__(mpl.rcParams, "savefig.jpeg_quality")
575575
if quality not in [0, 75, 95]: # default qualities.
576-
cbook.warn_deprecated(
576+
_api.warn_deprecated(
577577
"3.3", name="savefig.jpeg_quality", obj_type="rcParam",
578578
addendum="Set the quality using "
579579
"`pil_kwargs={'quality': ...}`; the future default "

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ def __init__(self, filename, *, keep_empty=True, metadata=None):
969969
'moddate': 'ModDate',
970970
}.get(key.lower(), key.lower().title())
971971
if canonical != key:
972-
cbook.warn_deprecated(
972+
_api.warn_deprecated(
973973
'3.3', message='Support for setting PDF metadata keys '
974974
'case-insensitively is deprecated since %(since)s and '
975975
'will be removed %(removal)s; '

lib/matplotlib/backends/backend_qt4.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from .. import cbook
1+
from .. import _api
22
from .backend_qt5 import (
33
backend_version, SPECIAL_KEYS,
44
SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS, # These are deprecated.
55
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureCanvasQT,
66
FigureManagerQT, NavigationToolbar2QT, SubplotToolQt, exception_handler)
77

88

9-
cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
9+
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")
1010

1111

1212
@_BackendQT5.export

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
Render to qt from agg
33
"""
44

5-
from .. import cbook
5+
from .. import _api
66
from .backend_qt5agg import (
77
_BackendQT5Agg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT)
88

99

10-
cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
10+
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")
1111

1212

1313
@_BackendQT5Agg.export

lib/matplotlib/backends/backend_qt4cairo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .. import cbook
1+
from .. import _api
22
from .backend_qt5cairo import _BackendQT5Cairo, FigureCanvasQTCairo
33

44

5-
cbook.warn_deprecated("3.3", name=__name__, obj_type="backend")
5+
_api.warn_deprecated("3.3", name=__name__, obj_type="backend")
66

77

88
@_BackendQT5Cairo.export

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class RendererWx(RendererBase):
142142

143143
def __init__(self, bitmap, dpi):
144144
"""Initialise a wxWindows renderer instance."""
145-
cbook.warn_deprecated(
145+
_api.warn_deprecated(
146146
"2.0", name="wx", obj_type="backend", removal="the future",
147147
alternative="wxagg", addendum="See the Matplotlib usage FAQ for "
148148
"more info on backends.")

lib/matplotlib/backends/qt_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def is_pyqt5():
185185
QT_RC_MAJOR_VERSION = int(QtCore.qVersion().split(".")[0])
186186

187187
if QT_RC_MAJOR_VERSION == 4:
188-
mpl.cbook.warn_deprecated("3.3", name="support for Qt4")
188+
_api.warn_deprecated("3.3", name="support for Qt4")
189189

190190

191191
def _devicePixelRatioF(obj):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from matplotlib import cbook
1+
from matplotlib import _api
22
from ._formsubplottool import UiSubplotTool
33

44

5-
cbook.warn_deprecated(
5+
_api.warn_deprecated(
66
"3.3", obj_type="module", name=__name__,
77
alternative="matplotlib.backends.backend_qt5.SubplotToolQt")
88
__all__ = ["UiSubplotTool"]

lib/matplotlib/cbook/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@
3030
import matplotlib
3131
from matplotlib import _api, _c_internal_utils
3232
from matplotlib._api.deprecation import (
33-
warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)
33+
MatplotlibDeprecationWarning, mplDeprecation)
3434

3535

3636
@_api.deprecated("3.4")
3737
def deprecated(*args, **kwargs):
3838
return _api.deprecated(*args, **kwargs)
3939

4040

41+
@_api.deprecated("3.4")
42+
def warn_deprecated(*args, **kwargs):
43+
_api.warn_deprecated(*args, **kwargs)
44+
45+
4146
def _get_running_interactive_framework():
4247
"""
4348
Return the interactive framework whose event loop is currently running, if
@@ -427,9 +432,9 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
427432
if isinstance(fname, os.PathLike):
428433
fname = os.fspath(fname)
429434
if "U" in flag:
430-
warn_deprecated("3.3", message="Passing a flag containing 'U' to "
431-
"to_filehandle() is deprecated since %(since)s and "
432-
"will be removed %(removal)s.")
435+
_api.warn_deprecated(
436+
"3.3", message="Passing a flag containing 'U' to to_filehandle() "
437+
"is deprecated since %(since)s and will be removed %(removal)s.")
433438
flag = flag.replace("U", "")
434439
if isinstance(fname, str):
435440
if fname.endswith('.gz'):
@@ -491,7 +496,7 @@ def get_sample_data(fname, asfileobj=True, *, np_load=False):
491496
if np_load:
492497
return np.load(path)
493498
else:
494-
warn_deprecated(
499+
_api.warn_deprecated(
495500
"3.3", message="In a future release, get_sample_data "
496501
"will automatically load numpy arrays. Set np_load to "
497502
"True to get the array and suppress this warning. Set "

0 commit comments

Comments
 (0)