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

Skip to content

Commit 37c7620

Browse files
committed
Deprecate more rc validators.
- validate_bool_maybe_none is now unused; if we really need it back we'd make it private and I'd anyways rather add machinery so that one can just specify it as `[bool, None]` (or `Optional[bool]`) in _prop_validators. - validate_hinting will become a plain list after the deprecation period. - validate_movie_writer makes it impossible to set movie.writer to a third-party animation writer, because that third-party module will necessarily first import matplotlib before being able to register its writer, and thus the matplotlibrc file will be parsed before the writer is registered. In any case, `MovieWriterRegistry.__getitem__` also raises an informative error on unknown writer names, which should be enough, so let's just accept any string.
1 parent 4db2b2b commit 37c7620

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ The following validators, defined in `.rcsetup`, are deprecated:
220220
``validate_movie_frame_fmt``, ``validate_axis_locator``,
221221
``validate_movie_html_fmt``, ``validate_grid_axis``,
222222
``validate_axes_titlelocation``, ``validate_toolbar``,
223-
``validate_ps_papersize``, ``validate_legend_log``. To test whether an rcParam
224-
value would be acceptable, one can test e.g. ``rc = RcParams(); rc[k] = v``
225-
raises an exception.
223+
``validate_ps_papersize``, ``validate_legend_loc``,
224+
``validate_bool_maybe_none``, ``validate_hinting``,
225+
``validate_movie_writers``.
226+
To test whether an rcParam value would be acceptable, one can test e.g. ``rc =
227+
RcParams(); rc[k] = v`` raises an exception.
226228

227229
Toggling axes navigation from the keyboard using "a" and digit keys
228230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/matplotlib/rcsetup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def validate_bool(b):
140140
raise ValueError('Could not convert "%s" to bool' % b)
141141

142142

143+
@cbook.deprecated("3.3")
143144
def validate_bool_maybe_none(b):
144145
"""Convert b to ``bool`` or raise, passing through *None*."""
145146
if isinstance(b, str):
@@ -646,7 +647,13 @@ def validate_markevery(s):
646647
'svg.fonttype', ['none', 'path'], _deprecated_since="3.3")
647648

648649

650+
@cbook.deprecated("3.3")
649651
def validate_hinting(s):
652+
return _validate_hinting(s)
653+
654+
655+
# Replace by plain list in _prop_validators after deprecation period.
656+
def _validate_hinting(s):
650657
if s in (True, False):
651658
cbook.warn_deprecated(
652659
"3.2", message="Support for setting the text.hinting rcParam to "
@@ -663,6 +670,7 @@ def validate_hinting(s):
663670
_deprecated_since="3.3")
664671

665672

673+
@cbook.deprecated("3.3")
666674
def validate_movie_writer(s):
667675
# writers.list() would only list actually available writers, but
668676
# FFMpeg.isAvailable is slow and not worth paying for at every import.
@@ -1133,7 +1141,7 @@ def _convert_validator_spec(key, conv):
11331141
'text.usetex': [False, validate_bool],
11341142
'text.latex.preamble': ['', _validate_tex_preamble],
11351143
'text.latex.preview': [False, validate_bool],
1136-
'text.hinting': ['auto', validate_hinting],
1144+
'text.hinting': ['auto', _validate_hinting],
11371145
'text.hinting_factor': [8, validate_int],
11381146
'text.kerning_factor': [0, validate_int],
11391147
'text.antialiased': [True, validate_bool],
@@ -1452,7 +1460,7 @@ def _convert_validator_spec(key, conv):
14521460
# Limit, in MB, of size of base64 encoded animation in HTML
14531461
# (i.e. IPython notebook)
14541462
'animation.embed_limit': [20, validate_float],
1455-
'animation.writer': ['ffmpeg', validate_movie_writer],
1463+
'animation.writer': ['ffmpeg', validate_string],
14561464
'animation.codec': ['h264', validate_string],
14571465
'animation.bitrate': [-1, validate_int],
14581466
# Controls image format when frames are written to disk

lib/matplotlib/tests/test_rcparams.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ def test_Bug_2543():
125125
# real test is that this does not raise
126126
assert validate_bool_maybe_none(None) is None
127127
assert validate_bool_maybe_none("none") is None
128-
129-
with pytest.raises(ValueError):
130-
validate_bool_maybe_none("blah")
128+
with pytest.raises(ValueError):
129+
validate_bool_maybe_none("blah")
131130
with pytest.raises(ValueError):
132131
validate_bool(None)
133132
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)