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

Skip to content

Commit 3ddd62c

Browse files
committed
Also deprecate ignorecase ValidateInStrings.
... by using re.I ("ignorecase") as marker for those.
1 parent 29fe439 commit 3ddd62c

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ The following validators, defined in `.rcsetup`, are deprecated:
219219
``validate_svg_fontset``, ``validate_pgf_texsystem``,
220220
``validate_movie_frame_fmt``, ``validate_axis_locator``,
221221
``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.
222+
``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.

lib/matplotlib/rcsetup.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def validate_backend(s):
269269

270270

271271
validate_toolbar = ValidateInStrings(
272-
'toolbar', ['None', 'toolbar2', 'toolmanager'], ignorecase=True)
272+
'toolbar', ['None', 'toolbar2', 'toolmanager'], ignorecase=True,
273+
_deprecated_since="3.3")
273274

274275

275276
def _make_nseq_validator(cls, n=None, allow_none=False):
@@ -478,7 +479,7 @@ def _update_savefig_format(value):
478479
['auto', 'letter', 'legal', 'ledger',
479480
'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10',
480481
'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'b10',
481-
], ignorecase=True)
482+
], ignorecase=True, _deprecated_since="3.3")
482483

483484

484485
def validate_ps_distiller(s):
@@ -639,7 +640,7 @@ def validate_markevery(s):
639640
'center right',
640641
'lower center',
641642
'upper center',
642-
'center'], ignorecase=True)
643+
'center'], ignorecase=True, _deprecated_since="3.3")
643644

644645
validate_svg_fonttype = ValidateInStrings(
645646
'svg.fonttype', ['none', 'path'], _deprecated_since="3.3")
@@ -985,17 +986,29 @@ def validate_webagg_address(s):
985986
'axes.titlelocation', ['left', 'center', 'right'], _deprecated_since="3.3")
986987

987988

989+
class _ignorecase(list):
990+
"""A marker class indicating that a list-of-str is case-insensitive."""
991+
992+
993+
def _convert_validator_spec(key, conv):
994+
if isinstance(conv, list):
995+
ignorecase = isinstance(conv, _ignorecase)
996+
return ValidateInStrings(key, conv, ignorecase=ignorecase)
997+
else:
998+
return conv
999+
1000+
9881001
# A map of key -> [value, converter].
989-
# Converters given as lists are converted to ValidateInStrings immediately
990-
# below.
1002+
# Converters given as lists or _ignorecase are converted to ValidateInStrings
1003+
# immediately below.
9911004
defaultParams = {
9921005
'backend': [_auto_backend_sentinel, validate_backend],
9931006
'backend_fallback': [True, validate_bool],
9941007
'webagg.port': [8988, validate_int],
9951008
'webagg.address': ['127.0.0.1', validate_webagg_address],
9961009
'webagg.open_in_browser': [True, validate_bool],
9971010
'webagg.port_retries': [50, validate_int],
998-
'toolbar': ['toolbar2', validate_toolbar],
1011+
'toolbar': ['toolbar2', _ignorecase(['none', 'toolbar2', 'toolmanager'])],
9991012
'datapath': [None, validate_any], # see _get_data_path_cached
10001013
'interactive': [False, validate_bool],
10011014
'timezone': ['UTC', validate_string],
@@ -1232,7 +1245,13 @@ def validate_webagg_address(s):
12321245

12331246
#legend properties
12341247
'legend.fancybox': [True, validate_bool],
1235-
'legend.loc': ['best', validate_legend_loc],
1248+
'legend.loc': ['best',
1249+
_ignorecase(['best',
1250+
'upper right', 'upper left',
1251+
'lower left', 'lower right', 'right',
1252+
'center left', 'center right',
1253+
'lower center', 'upper center',
1254+
'center'])],
12361255
# the number of points in the legend line
12371256
'legend.numpoints': [1, validate_int],
12381257
# the number of points in the legend line for scatter
@@ -1370,7 +1389,9 @@ def validate_webagg_address(s):
13701389
'tk.window_focus': [False, validate_bool],
13711390

13721391
# Set the papersize/type
1373-
'ps.papersize': ['letter', validate_ps_papersize],
1392+
'ps.papersize': ['letter',
1393+
_ignorecase(['auto', 'letter', 'legal', 'ledger',
1394+
*[f'{ab}{i}' for ab in 'ab' for i in range(11)]])],
13741395
'ps.useafm': [False, validate_bool],
13751396
# use ghostscript or xpdf to distill ps output
13761397
'ps.usedistiller': [False, validate_ps_distiller],
@@ -1460,7 +1481,5 @@ def validate_webagg_address(s):
14601481
# altogether. For that use `matplotlib.style.use('classic')`.
14611482
'_internal.classic_mode': [False, validate_bool]
14621483
}
1463-
defaultParams = {
1464-
k: [default,
1465-
ValidateInStrings(k, conv) if isinstance(conv, list) else conv]
1466-
for k, (default, conv) in defaultParams.items()}
1484+
defaultParams = {k: [default, _convert_validator_spec(k, conv)]
1485+
for k, (default, conv) in defaultParams.items()}

0 commit comments

Comments
 (0)