Skip to content

Commit 22a0be6

Browse files
authored
Merge pull request #18903 from timhoffm/more-suppress-depreaction-warning
Move cbook._suppress_matplotlib_deprecation_warning() from cbook to _api
2 parents 8768aec + 72cb913 commit 22a0be6

18 files changed

+36
-38
lines changed

lib/matplotlib/__init__.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
# cbook must import matplotlib only within function
106106
# definitions, so it is safe to import from it here.
107-
from . import cbook, docstring, rcsetup
107+
from . import _api, cbook, docstring, rcsetup
108108
from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
109109
from matplotlib.cbook import mplDeprecation # deprecated
110110
from matplotlib.rcsetup import validate_backend, cycler
@@ -670,7 +670,7 @@ def __getitem__(self, key):
670670
def __repr__(self):
671671
class_name = self.__class__.__name__
672672
indent = len(class_name) + 1
673-
with cbook._suppress_matplotlib_deprecation_warning():
673+
with _api.suppress_matplotlib_deprecation_warning():
674674
repr_split = pprint.pformat(dict(self), indent=1,
675675
width=80 - indent).split('\n')
676676
repr_indented = ('\n' + ' ' * indent).join(repr_split)
@@ -681,7 +681,7 @@ def __str__(self):
681681

682682
def __iter__(self):
683683
"""Yield sorted list of keys."""
684-
with cbook._suppress_matplotlib_deprecation_warning():
684+
with _api.suppress_matplotlib_deprecation_warning():
685685
yield from sorted(dict.__iter__(self))
686686

687687
def __len__(self):
@@ -845,10 +845,10 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
845845
if not use_default_template:
846846
return config_from_file
847847

848-
with cbook._suppress_matplotlib_deprecation_warning():
848+
with _api.suppress_matplotlib_deprecation_warning():
849849
config = RcParams({**rcParamsDefault, **config_from_file})
850850

851-
with cbook._suppress_matplotlib_deprecation_warning():
851+
with _api.suppress_matplotlib_deprecation_warning():
852852
if config['datapath'] is None:
853853
config['datapath'] = _get_data_path()
854854
else:
@@ -879,7 +879,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
879879
rcParams = RcParams() # The global instance.
880880
dict.update(rcParams, dict.items(rcParamsDefault))
881881
dict.update(rcParams, _rc_params_in_file(matplotlib_fname()))
882-
with cbook._suppress_matplotlib_deprecation_warning():
882+
with _api.suppress_matplotlib_deprecation_warning():
883883
rcParamsOrig = RcParams(rcParams.copy())
884884
# This also checks that all rcParams are indeed listed in the template.
885885
# Assigning to rcsetup.defaultParams is left only for backcompat.
@@ -987,7 +987,7 @@ def rcdefaults():
987987
"""
988988
# Deprecation warnings were already handled when creating rcParamsDefault,
989989
# no need to reemit them here.
990-
with cbook._suppress_matplotlib_deprecation_warning():
990+
with _api.suppress_matplotlib_deprecation_warning():
991991
from .style.core import STYLE_BLACKLIST
992992
rcParams.clear()
993993
rcParams.update({k: v for k, v in rcParamsDefault.items()
@@ -1003,7 +1003,7 @@ def rc_file_defaults():
10031003
"""
10041004
# Deprecation warnings were already handled when creating rcParamsOrig, no
10051005
# need to reemit them here.
1006-
with cbook._suppress_matplotlib_deprecation_warning():
1006+
with _api.suppress_matplotlib_deprecation_warning():
10071007
from .style.core import STYLE_BLACKLIST
10081008
rcParams.update({k: rcParamsOrig[k] for k in rcParamsOrig
10091009
if k not in STYLE_BLACKLIST})
@@ -1028,7 +1028,7 @@ def rc_file(fname, *, use_default_template=True):
10281028
"""
10291029
# Deprecation warnings were already handled in rc_params_from_file, no need
10301030
# to reemit them here.
1031-
with cbook._suppress_matplotlib_deprecation_warning():
1031+
with _api.suppress_matplotlib_deprecation_warning():
10321032
from .style.core import STYLE_BLACKLIST
10331033
rc_from_file = rc_params_from_file(
10341034
fname, use_default_template=use_default_template)

lib/matplotlib/cbook/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
deprecated, warn_deprecated,
3636
_rename_parameter, _delete_parameter, _make_keyword_only,
3737
_deprecate_method_override, _deprecate_privatize_attribute,
38-
suppress_matplotlib_deprecation_warning as
39-
_suppress_matplotlib_deprecation_warning,
4038
MatplotlibDeprecationWarning, mplDeprecation)
4139

4240

lib/matplotlib/mathtext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def factory(cls, glue_type):
384384
return cls._types[glue_type]
385385

386386

387-
with cbook._suppress_matplotlib_deprecation_warning():
387+
with _api.suppress_matplotlib_deprecation_warning():
388388
GlueSpec._types = {k: GlueSpec(**v._asdict())
389389
for k, v in _mathtext._GlueSpec._named.items()}
390390

lib/matplotlib/style/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import warnings
2020

2121
import matplotlib as mpl
22-
from matplotlib import cbook, rc_params_from_file, rcParamsDefault
22+
from matplotlib import _api, cbook, rc_params_from_file, rcParamsDefault
2323

2424
_log = logging.getLogger(__name__)
2525

@@ -106,7 +106,7 @@ def use(style):
106106
elif style == 'default':
107107
# Deprecation warnings were already handled when creating
108108
# rcParamsDefault, no need to reemit them here.
109-
with cbook._suppress_matplotlib_deprecation_warning():
109+
with _api.suppress_matplotlib_deprecation_warning():
110110
_apply_style(rcParamsDefault, warn=False)
111111
elif style in library:
112112
_apply_style(library[style])

lib/matplotlib/testing/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77

88
import matplotlib as mpl
9-
from matplotlib import cbook
9+
from matplotlib import _api
1010

1111
_log = logging.getLogger(__name__)
1212

@@ -37,7 +37,7 @@ def setup():
3737

3838
mpl.use('Agg')
3939

40-
with cbook._suppress_matplotlib_deprecation_warning():
40+
with _api.suppress_matplotlib_deprecation_warning():
4141
mpl.rcdefaults() # Start with all defaults
4242

4343
# These settings *must* be hardcoded for running the comparison tests and

lib/matplotlib/testing/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import sys
33
import matplotlib
4-
from matplotlib import cbook
4+
from matplotlib import _api, cbook
55

66

77
def pytest_configure(config):
@@ -79,7 +79,7 @@ def mpl_test_settings(request):
7979
style, = style_marker.args
8080

8181
matplotlib.testing.setup()
82-
with cbook._suppress_matplotlib_deprecation_warning():
82+
with _api.suppress_matplotlib_deprecation_warning():
8383
if backend is not None:
8484
# This import must come after setup() so it doesn't load the
8585
# default backend prematurely.

lib/matplotlib/tests/test_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5664,7 +5664,7 @@ def test_ls_ds_conflict():
56645664
# Passing the drawstyle with the linestyle is deprecated since 3.1.
56655665
# We still need to test this until it's removed from the code.
56665666
# But we don't want to see the deprecation warning in the test.
5667-
with matplotlib.cbook._suppress_matplotlib_deprecation_warning(), \
5667+
with matplotlib._api.suppress_matplotlib_deprecation_warning(), \
56685668
pytest.raises(ValueError):
56695669
plt.plot(range(32), linestyle='steps-pre:', drawstyle='steps-post')
56705670

lib/matplotlib/tests/test_cbook.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ def test_sanitize_sequence():
329329
@pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping)
330330
def test_normalize_kwargs_fail(inp, kwargs_to_norm):
331331
with pytest.raises(TypeError), \
332-
cbook._suppress_matplotlib_deprecation_warning():
332+
_api.suppress_matplotlib_deprecation_warning():
333333
cbook.normalize_kwargs(inp, **kwargs_to_norm)
334334

335335

336336
@pytest.mark.parametrize('inp, expected, kwargs_to_norm',
337337
pass_mapping)
338338
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):
339-
with cbook._suppress_matplotlib_deprecation_warning():
339+
with _api.suppress_matplotlib_deprecation_warning():
340340
# No other warning should be emitted.
341341
assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
342342

lib/matplotlib/tests/test_mathtext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib as mpl
99
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1010
import matplotlib.pyplot as plt
11-
from matplotlib import cbook, mathtext
11+
from matplotlib import _api, mathtext
1212

1313

1414
# If test is removed, use None as placeholder
@@ -357,7 +357,7 @@ def test_math_to_image(tmpdir):
357357

358358

359359
def test_mathtext_to_png(tmpdir):
360-
with cbook._suppress_matplotlib_deprecation_warning():
360+
with _api.suppress_matplotlib_deprecation_warning():
361361
mt = mathtext.MathTextParser('bitmap')
362362
mt.to_png(str(tmpdir.join('example.png')), '$x^2$')
363363
mt.to_png(io.BytesIO(), '$x^2$')

lib/matplotlib/tests/test_rcparams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
import matplotlib as mpl
13-
from matplotlib import cbook
13+
from matplotlib import _api
1414
import matplotlib.pyplot as plt
1515
import matplotlib.colors as mcolors
1616
import numpy as np
@@ -125,7 +125,7 @@ def test_Bug_2543():
125125
# We filter warnings at this stage since a number of them are raised
126126
# for deprecated rcparams as they should. We don't want these in the
127127
# printed in the test suite.
128-
with cbook._suppress_matplotlib_deprecation_warning():
128+
with _api.suppress_matplotlib_deprecation_warning():
129129
with mpl.rc_context():
130130
_copy = mpl.rcParams.copy()
131131
for key in _copy:

lib/matplotlib/tests/test_ticker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import matplotlib as mpl
11-
from matplotlib import cbook
11+
from matplotlib import _api
1212
import matplotlib.pyplot as plt
1313
import matplotlib.ticker as mticker
1414

@@ -454,7 +454,7 @@ class TestIndexFormatter:
454454
(2, 'label2'),
455455
(2.5, '')])
456456
def test_formatting(self, x, label):
457-
with cbook._suppress_matplotlib_deprecation_warning():
457+
with _api.suppress_matplotlib_deprecation_warning():
458458
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
459459
assert formatter(x) == label
460460

lib/matplotlib/ticker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ def _if_refresh_overridden_call_and_emit_deprec(locator):
16601660
"%(removal)s. You are using a third-party locator that overrides "
16611661
"the refresh() method; this locator should instead perform any "
16621662
"required processing in __call__().")
1663-
with cbook._suppress_matplotlib_deprecation_warning():
1663+
with _api.suppress_matplotlib_deprecation_warning():
16641664
locator.refresh()
16651665

16661666

lib/matplotlib/widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def begin_typing(self, x):
835835
else:
836836
# If not using toolmanager, disable all keypress-related rcParams.
837837
# Avoid spurious warnings if keymaps are getting deprecated.
838-
with cbook._suppress_matplotlib_deprecation_warning():
838+
with _api.suppress_matplotlib_deprecation_warning():
839839
stack.enter_context(mpl.rc_context(
840840
{k: [] for k in mpl.rcParams if k.startswith("keymap.")}))
841841

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from matplotlib import cbook
1+
from matplotlib import _api
22
from mpl_toolkits.axes_grid1.parasite_axes import (
33
host_axes_class_factory, parasite_axes_class_factory,
44
parasite_axes_auxtrans_class_factory, subplot_class_factory)
@@ -8,5 +8,5 @@
88
ParasiteAxes = parasite_axes_class_factory(Axes)
99
HostAxes = host_axes_class_factory(Axes)
1010
SubplotHost = subplot_class_factory(HostAxes)
11-
with cbook._suppress_matplotlib_deprecation_warning():
11+
with _api.suppress_matplotlib_deprecation_warning():
1212
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)

lib/mpl_toolkits/axes_grid1/parasite_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
166166

167167

168168
# Also deprecated.
169-
with cbook._suppress_matplotlib_deprecation_warning():
169+
with _api.suppress_matplotlib_deprecation_warning():
170170
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)
171171

172172

lib/mpl_toolkits/axisartist/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from matplotlib import cbook
1+
from matplotlib import _api
22
from .axislines import (
33
Axes, AxesZero, AxisArtistHelper, AxisArtistHelperRectlinear,
44
GridHelperBase, GridHelperRectlinear, Subplot, SubplotZero)
@@ -13,5 +13,5 @@
1313
ParasiteAxes = parasite_axes_class_factory(Axes)
1414
HostAxes = host_axes_class_factory(Axes)
1515
SubplotHost = subplot_class_factory(HostAxes)
16-
with cbook._suppress_matplotlib_deprecation_warning():
16+
with _api.suppress_matplotlib_deprecation_warning():
1717
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from matplotlib import cbook
1+
from matplotlib import _api
22
from mpl_toolkits.axes_grid1.parasite_axes import (
33
host_axes_class_factory, parasite_axes_class_factory,
44
parasite_axes_auxtrans_class_factory, subplot_class_factory)
@@ -8,5 +8,5 @@
88
ParasiteAxes = parasite_axes_class_factory(Axes)
99
HostAxes = host_axes_class_factory(Axes)
1010
SubplotHost = subplot_class_factory(HostAxes)
11-
with cbook._suppress_matplotlib_deprecation_warning():
11+
with _api.suppress_matplotlib_deprecation_warning():
1212
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)

lib/mpl_toolkits/tests/test_axisartist_axislines.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from matplotlib import cbook
2+
from matplotlib import _api
33
import matplotlib.pyplot as plt
44
from matplotlib.testing.decorators import image_comparison
55
from matplotlib.transforms import IdentityTransform
@@ -86,7 +86,7 @@ def test_ParasiteAxesAuxTrans(parasite_cls):
8686
ax1 = SubplotHost(fig, 1, 3, i+1)
8787
fig.add_subplot(ax1)
8888

89-
with cbook._suppress_matplotlib_deprecation_warning():
89+
with _api.suppress_matplotlib_deprecation_warning():
9090
ax2 = parasite_cls(ax1, IdentityTransform())
9191
ax1.parasites.append(ax2)
9292
if name.startswith('pcolor'):

0 commit comments

Comments
 (0)