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

Skip to content

Commit 29fe439

Browse files
authored
Merge pull request #16483 from anntzer/vsil
Deprecate most ValidateInStrings validators.
2 parents 3a8e75e + b32a06a commit 29fe439

File tree

2 files changed

+68
-44
lines changed

2 files changed

+68
-44
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,14 @@ The *clear_temp* parameter and attribute of `.FileMovieWriter` is
211211
deprecated. In the future, files placed in a temporary directory (using
212212
``frame_prefix=None``, the default) will be cleared; files placed elsewhere
213213
will not.
214+
215+
Deprecated rcParams validators
216+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217+
The following validators, defined in `.rcsetup`, are deprecated:
218+
``validate_fontset``, ``validate_mathtext_default``, ``validate_alignment``,
219+
``validate_svg_fontset``, ``validate_pgf_texsystem``,
220+
``validate_movie_frame_fmt``, ``validate_axis_locator``,
221+
``validate_movie_html_fmt``, ``validate_grid_axis``,
222+
``validate_axes_titlelocation``. To test whether an rcParam value would
223+
be acceptable, one can test e.g. ``rc = RcParams(); rc[k] = v`` raises an
224+
exception.

lib/matplotlib/rcsetup.py

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050

5151

5252
class ValidateInStrings:
53-
def __init__(self, key, valid, ignorecase=False):
53+
def __init__(self, key, valid, ignorecase=False, *,
54+
_deprecated_since=None):
5455
"""*valid* is a list of legal strings."""
5556
self.key = key
5657
self.ignorecase = ignorecase
58+
self._deprecated_since = _deprecated_since
5759

5860
def func(s):
5961
if ignorecase:
@@ -63,6 +65,10 @@ def func(s):
6365
self.valid = {func(k): k for k in valid}
6466

6567
def __call__(self, s):
68+
if self._deprecated_since:
69+
name, = (k for k, v in globals().items() if v is self)
70+
cbook.warn_deprecated(
71+
self._deprecated_since, name=name, obj_type="function")
6672
if self.ignorecase:
6773
s = s.lower()
6874
if s in self.valid:
@@ -352,7 +358,7 @@ def validate_color(s):
352358
validate_colorlist = _listify_validator(
353359
validate_color, allow_stringlist=True, doc='return a list of colorspecs')
354360
validate_orientation = ValidateInStrings(
355-
'orientation', ['landscape', 'portrait'])
361+
'orientation', ['landscape', 'portrait'], _deprecated_since="3.3")
356362

357363

358364
def validate_aspect(s):
@@ -408,15 +414,15 @@ def validate_font_properties(s):
408414

409415
validate_fontset = ValidateInStrings(
410416
'fontset',
411-
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'])
417+
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'],
418+
_deprecated_since="3.3")
412419
validate_mathtext_default = ValidateInStrings(
413-
'default', "rm cal it tt sf bf default bb frak scr regular".split())
414-
415-
420+
'default', "rm cal it tt sf bf default bb frak scr regular".split(),
421+
_deprecated_since="3.3")
416422
_validate_alignment = ValidateInStrings(
417423
'alignment',
418-
['center', 'top', 'bottom', 'baseline',
419-
'center_baseline'])
424+
['center', 'top', 'bottom', 'baseline', 'center_baseline'],
425+
_deprecated_since="3.3")
420426

421427

422428
def validate_whiskers(s):
@@ -635,7 +641,8 @@ def validate_markevery(s):
635641
'upper center',
636642
'center'], ignorecase=True)
637643

638-
validate_svg_fonttype = ValidateInStrings('svg.fonttype', ['none', 'path'])
644+
validate_svg_fonttype = ValidateInStrings(
645+
'svg.fonttype', ['none', 'path'], _deprecated_since="3.3")
639646

640647

641648
def validate_hinting(s):
@@ -650,8 +657,9 @@ def validate_hinting(s):
650657
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")
651658

652659

653-
validate_pgf_texsystem = ValidateInStrings('pgf.texsystem',
654-
['xelatex', 'lualatex', 'pdflatex'])
660+
validate_pgf_texsystem = ValidateInStrings(
661+
'pgf.texsystem', ['xelatex', 'lualatex', 'pdflatex'],
662+
_deprecated_since="3.3")
655663

656664

657665
def validate_movie_writer(s):
@@ -665,12 +673,13 @@ def validate_movie_writer(s):
665673

666674

667675
validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
668-
['png', 'jpeg', 'tiff', 'raw', 'rgba'])
676+
['png', 'jpeg', 'tiff', 'raw', 'rgba'], _deprecated_since="3.3")
669677

670-
validate_axis_locator = ValidateInStrings('major', ['minor', 'both', 'major'])
678+
validate_axis_locator = ValidateInStrings(
679+
'major', ['minor', 'both', 'major'], _deprecated_since="3.3")
671680

672681
validate_movie_html_fmt = ValidateInStrings('animation.html',
673-
['html5', 'jshtml', 'none'])
682+
['html5', 'jshtml', 'none'], _deprecated_since="3.3")
674683

675684

676685
def validate_bbox(s):
@@ -723,7 +732,8 @@ def _validate_greaterequal0_lessequal1(s):
723732
}
724733

725734

726-
validate_grid_axis = ValidateInStrings('axes.grid.axis', ['x', 'y', 'both'])
735+
validate_grid_axis = ValidateInStrings(
736+
'axes.grid.axis', ['x', 'y', 'both'], _deprecated_since="3.3")
727737

728738

729739
def validate_hatch(s):
@@ -971,15 +981,13 @@ def validate_webagg_address(s):
971981
raise ValueError("'webagg.address' is not a valid IP address")
972982

973983

974-
validate_axes_titlelocation = ValidateInStrings('axes.titlelocation',
975-
['left', 'center', 'right'])
976-
_validate_xaxis_labellocation = ValidateInStrings('xaxis.labellocation',
977-
['left', 'center', 'right'])
978-
_validate_yaxis_labellocation = ValidateInStrings('yaxis.labellocation',
979-
['bottom', 'center', 'top'])
984+
validate_axes_titlelocation = ValidateInStrings(
985+
'axes.titlelocation', ['left', 'center', 'right'], _deprecated_since="3.3")
980986

981987

982-
# a map from key -> value, converter
988+
# A map of key -> [value, converter].
989+
# Converters given as lists are converted to ValidateInStrings immediately
990+
# below.
983991
defaultParams = {
984992
'backend': [_auto_backend_sentinel, validate_backend],
985993
'backend_fallback': [True, validate_bool],
@@ -1124,16 +1132,19 @@ def validate_webagg_address(s):
11241132
'mathtext.it': ['sans:italic', validate_font_properties],
11251133
'mathtext.bf': ['sans:bold', validate_font_properties],
11261134
'mathtext.sf': ['sans', validate_font_properties],
1127-
'mathtext.fontset': ['dejavusans', validate_fontset],
1128-
'mathtext.default': ['it', validate_mathtext_default],
1135+
'mathtext.fontset': [
1136+
'dejavusans',
1137+
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom']],
1138+
'mathtext.default': [
1139+
'it',
1140+
['rm', 'cal', 'it', 'tt', 'sf', 'bf', 'default', 'bb', 'frak', 'scr', 'regular']],
11291141
'mathtext.fallback_to_cm': [True, validate_bool],
11301142

11311143
'image.aspect': ['equal', validate_aspect], # equal, auto, a number
11321144
'image.interpolation': ['antialiased', validate_string],
11331145
'image.cmap': ['viridis', validate_string], # gray, jet, etc.
11341146
'image.lut': [256, validate_int], # lookup table
1135-
'image.origin': ['upper',
1136-
ValidateInStrings('image.origin', ['upper', 'lower'])],
1147+
'image.origin': ['upper', ['upper', 'lower']],
11371148
'image.resample': [True, validate_bool],
11381149
# Specify whether vector graphics backends will combine all images on a
11391150
# set of axes into a single composite image
@@ -1147,8 +1158,8 @@ def validate_webagg_address(s):
11471158
'errorbar.capsize': [0, validate_float],
11481159

11491160
# axis props
1150-
'xaxis.labellocation': ['center', _validate_xaxis_labellocation], # alignment of x axis title
1151-
'yaxis.labellocation': ['center', _validate_yaxis_labellocation], # alignment of y axis title
1161+
'xaxis.labellocation': ['center', ['left', 'center', 'right']], # alignment of x axis title
1162+
'yaxis.labellocation': ['center', ['bottom', 'center', 'top']], # alignment of y axis title
11521163

11531164
# axes props
11541165
'axes.axisbelow': ['line', validate_axisbelow],
@@ -1163,16 +1174,14 @@ def validate_webagg_address(s):
11631174

11641175
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
11651176
# axes title
1166-
'axes.titlelocation': ['center', validate_axes_titlelocation], # alignment of axes title
1177+
'axes.titlelocation': ['center', ['left', 'center', 'right']], # alignment of axes title
11671178
'axes.titleweight': ['normal', validate_fontweight], # font weight of axes title
11681179
'axes.titlecolor': ['auto', validate_color_or_auto], # font color of axes title
11691180
'axes.titlepad': [6.0, validate_float], # pad from axes top to title in points
11701181
'axes.grid': [False, validate_bool], # display grid or not
1171-
'axes.grid.which': ['major', validate_axis_locator], # set whether the gid are by
1172-
# default draw on 'major'
1173-
# 'minor' or 'both' kind of
1174-
# axis locator
1175-
'axes.grid.axis': ['both', validate_grid_axis], # grid type:
1182+
'axes.grid.which': ['major', ['minor', 'both', 'major']], # set whether the grid is drawn on
1183+
# 'major' 'minor' or 'both' ticks
1184+
'axes.grid.axis': ['both', ['x', 'y', 'both']], # grid type:
11761185
# 'x', 'y', or 'both'
11771186
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
11781187
# x any y labels
@@ -1201,9 +1210,7 @@ def validate_webagg_address(s):
12011210
validate_cycler],
12021211
# If 'data', axes limits are set close to the data.
12031212
# If 'round_numbers' axes limits are set to the nearest round numbers.
1204-
'axes.autolimit_mode': [
1205-
'data',
1206-
ValidateInStrings('autolimit_mode', ['data', 'round_numbers'])],
1213+
'axes.autolimit_mode': ['data', ['data', 'round_numbers']],
12071214
'axes.xmargin': [0.05, _range_validators["0 <= x <= 1"]],
12081215
'axes.ymargin': [0.05, _range_validators["0 <= x <= 1"]],
12091216

@@ -1278,7 +1285,8 @@ def validate_webagg_address(s):
12781285
# fontsize of the xtick labels
12791286
'xtick.labelsize': ['medium', validate_fontsize],
12801287
'xtick.direction': ['out', validate_string], # direction of xticks
1281-
'xtick.alignment': ["center", _validate_alignment],
1288+
'xtick.alignment': ['center',
1289+
['center', 'top', 'bottom', 'baseline', 'center_baseline']],
12821290

12831291
'ytick.left': [True, validate_bool], # draw ticks on the left side
12841292
'ytick.right': [False, validate_bool], # draw ticks on the right side
@@ -1300,7 +1308,8 @@ def validate_webagg_address(s):
13001308
# fontsize of the ytick labels
13011309
'ytick.labelsize': ['medium', validate_fontsize],
13021310
'ytick.direction': ['out', validate_string], # direction of yticks
1303-
'ytick.alignment': ["center_baseline", _validate_alignment],
1311+
'ytick.alignment': ['center_baseline',
1312+
['center', 'top', 'bottom', 'baseline', 'center_baseline']],
13041313

13051314
'grid.color': ['#b0b0b0', validate_color], # grid color
13061315
'grid.linestyle': ['-', _validate_linestyle], # solid
@@ -1346,7 +1355,7 @@ def validate_webagg_address(s):
13461355
'savefig.dpi': ['figure', validate_dpi], # DPI
13471356
'savefig.facecolor': ['white', validate_color],
13481357
'savefig.edgecolor': ['white', validate_color],
1349-
'savefig.orientation': ['portrait', validate_orientation],
1358+
'savefig.orientation': ['portrait', ['landscape', 'portrait']],
13501359
'savefig.jpeg_quality': [95, validate_int],
13511360
# value checked by backend at runtime
13521361
'savefig.format': ['png', _update_savefig_format],
@@ -1376,7 +1385,7 @@ def validate_webagg_address(s):
13761385
'pdf.fonttype': [3, validate_fonttype], # 3 (Type3) or 42 (Truetype)
13771386

13781387
# choose latex application for creating pdf files (xelatex/lualatex)
1379-
'pgf.texsystem': ['xelatex', validate_pgf_texsystem],
1388+
'pgf.texsystem': ['xelatex', ['xelatex', 'lualatex', 'pdflatex']],
13801389
# use matplotlib rc settings for font configuration
13811390
'pgf.rcfonts': [True, validate_bool],
13821391
# provide a custom preamble for the latex process
@@ -1385,7 +1394,7 @@ def validate_webagg_address(s):
13851394
# write raster image data directly into the svg file
13861395
'svg.image_inline': [True, validate_bool],
13871396
# True to save all characters as paths in the SVG
1388-
'svg.fonttype': ['path', validate_svg_fonttype],
1397+
'svg.fonttype': ['path', ['none', 'path']],
13891398
'svg.hashsalt': [None, validate_string_or_None],
13901399

13911400
# set this when you want to generate hardcopy docstring
@@ -1419,15 +1428,15 @@ def validate_webagg_address(s):
14191428
'keymap.copy': [['ctrl+c', 'cmd+c'], validate_stringlist],
14201429

14211430
# Animation settings
1422-
'animation.html': ['none', validate_movie_html_fmt],
1431+
'animation.html': ['none', ['html5', 'jshtml', 'none']],
14231432
# Limit, in MB, of size of base64 encoded animation in HTML
14241433
# (i.e. IPython notebook)
14251434
'animation.embed_limit': [20, validate_float],
14261435
'animation.writer': ['ffmpeg', validate_movie_writer],
14271436
'animation.codec': ['h264', validate_string],
14281437
'animation.bitrate': [-1, validate_int],
14291438
# Controls image format when frames are written to disk
1430-
'animation.frame_format': ['png', validate_movie_frame_fmt],
1439+
'animation.frame_format': ['png', ['png', 'jpeg', 'tiff', 'raw', 'rgba']],
14311440
# Additional arguments for HTML writer
14321441
'animation.html_args': [[], validate_stringlist],
14331442
# Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
@@ -1451,3 +1460,7 @@ def validate_webagg_address(s):
14511460
# altogether. For that use `matplotlib.style.use('classic')`.
14521461
'_internal.classic_mode': [False, validate_bool]
14531462
}
1463+
defaultParams = {
1464+
k: [default,
1465+
ValidateInStrings(k, conv) if isinstance(conv, list) else conv]
1466+
for k, (default, conv) in defaultParams.items()}

0 commit comments

Comments
 (0)