File tree 4 files changed +30
-6
lines changed
api/next_api_changes/behavior
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 17
17
import warnings
18
18
19
19
import matplotlib
20
- from matplotlib ._api import MatplotlibDeprecationWarning
21
20
import sphinx
22
21
23
22
from datetime import datetime
@@ -117,7 +116,7 @@ def _check_dependencies():
117
116
118
117
# we should ignore warnings coming from importing deprecated modules for
119
118
# autodoc purposes, as this will disappear automatically when they are removed
120
- warnings .filterwarnings ('ignore' , category = MatplotlibDeprecationWarning ,
119
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning ,
121
120
module = 'importlib' , # used by sphinx.autodoc.importer
122
121
message = r'(\n|.)*module was deprecated.*' )
123
122
@@ -126,7 +125,7 @@ def _check_dependencies():
126
125
127
126
# make sure to ignore warnings that stem from simply inspecting deprecated
128
127
# class-level attributes
129
- warnings .filterwarnings ('ignore' , category = MatplotlibDeprecationWarning ,
128
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning ,
130
129
module = 'sphinx.util.inspect' )
131
130
132
131
# missing-references names matches sphinx>=3 behavior, so we can't be nitpicky
Original file line number Diff line number Diff line change 17
17
import warnings
18
18
19
19
20
- class MatplotlibDeprecationWarning (UserWarning ):
20
+ class MatplotlibDeprecationWarning (DeprecationWarning ):
21
21
"""
22
22
A class for issuing deprecation warnings for Matplotlib users.
23
23
Original file line number Diff line number Diff line change 8
8
9
9
import matplotlib as mpl
10
10
from matplotlib import cbook , rcParams
11
+ from matplotlib ._api .deprecation import MatplotlibDeprecationWarning
11
12
from matplotlib .testing .decorators import image_comparison , check_figures_equal
12
13
from matplotlib .axes import Axes
13
14
from matplotlib .figure import Figure
14
15
from matplotlib .ticker import AutoMinorLocator , FixedFormatter , ScalarFormatter
15
16
import matplotlib .pyplot as plt
16
17
import matplotlib .dates as mdates
17
18
import matplotlib .gridspec as gridspec
18
- from matplotlib .cbook import MatplotlibDeprecationWarning
19
19
import numpy as np
20
20
import pytest
21
21
@@ -150,7 +150,7 @@ def test_figure_legend():
150
150
def test_gca ():
151
151
fig = plt .figure ()
152
152
153
- with pytest .warns (UserWarning ):
153
+ with pytest .warns (MatplotlibDeprecationWarning ):
154
154
# empty call to add_axes() will throw deprecation warning
155
155
assert fig .add_axes () is None
156
156
You can’t perform that action at this time.
0 commit comments