File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed
api/next_api_changes/behavior Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 1+ ``MatplotlibDeprecationWarning `` now subclasses ``DeprecationWarning ``
2+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+ Historically, it has not been possible to filter
4+ ``MatplotlibDeprecationWarning ``\s by checking for ``DeprecationWarning ``,
5+ since we subclass ``UserWarning `` directly.
6+
7+ The decision to not subclass DeprecationWarning has to do with a decision from
8+ core Python in the 2.x days to not show DeprecationWarnings to users. However,
9+ there is now a more sophisticated filter in place (see
10+ https://www.python.org/dev/peps/pep-0565/).
11+
12+ Users will now see ``MatplotlibDeprecationWarning `` only during interactive
13+ sessions, and these can be silenced by the standard mechanism:
14+
15+ .. code :: python
16+
17+ warnings.filterwarnings(" ignore" , category = DeprecationWarning )
18+
19+ Library authors must now enable ``DeprecationWarning ``\s explicitly in order
20+ for (non-interactive) CI/CD pipelines to report back these warnings, as is
21+ standard for the rest of the Python ecosystem:
22+
23+ .. code :: python
24+
25+ warnings.filterwarnings(" always" , DeprecationWarning )
Original file line number Diff line number Diff line change 1717import warnings
1818
1919import matplotlib
20- from matplotlib ._api import MatplotlibDeprecationWarning
2120import sphinx
2221
2322from datetime import datetime
@@ -117,7 +116,7 @@ def _check_dependencies():
117116
118117# we should ignore warnings coming from importing deprecated modules for
119118# autodoc purposes, as this will disappear automatically when they are removed
120- warnings .filterwarnings ('ignore' , category = MatplotlibDeprecationWarning ,
119+ warnings .filterwarnings ('ignore' , category = DeprecationWarning ,
121120 module = 'importlib' , # used by sphinx.autodoc.importer
122121 message = r'(\n|.)*module was deprecated.*' )
123122
@@ -126,7 +125,7 @@ def _check_dependencies():
126125
127126# make sure to ignore warnings that stem from simply inspecting deprecated
128127# class-level attributes
129- warnings .filterwarnings ('ignore' , category = MatplotlibDeprecationWarning ,
128+ warnings .filterwarnings ('ignore' , category = DeprecationWarning ,
130129 module = 'sphinx.util.inspect' )
131130
132131# missing-references names matches sphinx>=3 behavior, so we can't be nitpicky
Original file line number Diff line number Diff line change 1717import warnings
1818
1919
20- class MatplotlibDeprecationWarning (UserWarning ):
20+ class MatplotlibDeprecationWarning (DeprecationWarning ):
2121 """
2222 A class for issuing deprecation warnings for Matplotlib users.
2323
Original file line number Diff line number Diff line change 88
99import matplotlib as mpl
1010from matplotlib import cbook , rcParams
11+ from matplotlib ._api .deprecation import MatplotlibDeprecationWarning
1112from matplotlib .testing .decorators import image_comparison , check_figures_equal
1213from matplotlib .axes import Axes
1314from matplotlib .figure import Figure
1415from matplotlib .ticker import AutoMinorLocator , FixedFormatter , ScalarFormatter
1516import matplotlib .pyplot as plt
1617import matplotlib .dates as mdates
1718import matplotlib .gridspec as gridspec
18- from matplotlib .cbook import MatplotlibDeprecationWarning
1919import numpy as np
2020import pytest
2121
@@ -150,7 +150,7 @@ def test_figure_legend():
150150def test_gca ():
151151 fig = plt .figure ()
152152
153- with pytest .warns (UserWarning ):
153+ with pytest .warns (MatplotlibDeprecationWarning ):
154154 # empty call to add_axes() will throw deprecation warning
155155 assert fig .add_axes () is None
156156
You can’t perform that action at this time.
0 commit comments