Skip to content

Commit d2aa685

Browse files
committed
Remove deprecated rcParam accepted values.
1 parent 2d31dfa commit d2aa685

File tree

3 files changed

+28
-50
lines changed

3 files changed

+28
-50
lines changed

doc/api/next_api_changes/removals/19901-ES.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ The following validators, defined in `.rcsetup`, have been removed:
99
``validate_nseq_float``, ``validate_nseq_int``, ``validate_orientation``,
1010
``validate_pgf_texsystem``, ``validate_ps_papersize``,
1111
``validate_svg_fontset``, ``validate_toolbar``, ``validate_webagg_address``.
12+
13+
Stricter rcParam validation
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
:rc:`axes.axisbelow` no longer accepts strings starting with "line"
16+
(case-insensitive) as "line"; use "line" (case-sensitive) instead.
17+
18+
The :rc:`text.latex.preamble` and :rc:`pdf.preamble` no longer accept
19+
non-string values.
20+
21+
All ``*.linestyle`` rcParams no longer accept ``offset = None``; set the offset
22+
to 0 instead.

lib/matplotlib/rcsetup.py

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -166,42 +166,13 @@ def _validate_date_int_mult(s):
166166
mdates._rcParam_helper.set_int_mult(s)
167167

168168

169-
def _validate_tex_preamble(s):
170-
if s is None or s == 'None':
171-
_api.warn_deprecated(
172-
"3.3", message="Support for setting the 'text.latex.preamble' or "
173-
"'pgf.preamble' rcParam to None is deprecated since %(since)s and "
174-
"will be removed %(removal)s; set it to an empty string instead.")
175-
return ""
176-
try:
177-
if isinstance(s, str):
178-
return s
179-
elif np.iterable(s):
180-
_api.warn_deprecated(
181-
"3.3", message="Support for setting the 'text.latex.preamble' "
182-
"or 'pgf.preamble' rcParam to a list of strings is deprecated "
183-
"since %(since)s and will be removed %(removal)s; set it to a "
184-
"single string instead.")
185-
return '\n'.join(s)
186-
else:
187-
raise TypeError
188-
except TypeError as e:
189-
raise ValueError('Could not convert "%s" to string' % s) from e
190-
191-
192169
def validate_axisbelow(s):
193170
try:
194171
return validate_bool(s)
195172
except ValueError:
196173
if isinstance(s, str):
197174
if s == 'line':
198175
return 'line'
199-
if s.lower().startswith('line'):
200-
_api.warn_deprecated(
201-
"3.3", message=f"Support for setting axes.axisbelow to "
202-
f"{s!r} to mean 'line' is deprecated since %(since)s and "
203-
f"will be removed %(removal)s; set it to 'line' instead.")
204-
return 'line'
205176
raise ValueError('%s cannot be interpreted as'
206177
' True, False, or "line"' % s)
207178

@@ -466,25 +437,20 @@ def _is_iterable_not_string_like(x):
466437
# nonsensically interpreted as sequences of numbers (codepoints).
467438
return np.iterable(x) and not isinstance(x, (str, bytes, bytearray))
468439

469-
# (offset, (on, off, on, off, ...))
470-
if (_is_iterable_not_string_like(ls)
471-
and len(ls) == 2
472-
and isinstance(ls[0], (type(None), Number))
473-
and _is_iterable_not_string_like(ls[1])
474-
and len(ls[1]) % 2 == 0
475-
and all(isinstance(elem, Number) for elem in ls[1])):
476-
if ls[0] is None:
477-
_api.warn_deprecated(
478-
"3.3", message="Passing the dash offset as None is deprecated "
479-
"since %(since)s and support for it will be removed "
480-
"%(removal)s; pass it as zero instead.")
481-
ls = (0, ls[1])
482-
return ls
483-
# For backcompat: (on, off, on, off, ...); the offset is implicitly None.
484-
if (_is_iterable_not_string_like(ls)
485-
and len(ls) % 2 == 0
486-
and all(isinstance(elem, Number) for elem in ls)):
487-
return (0, ls)
440+
if _is_iterable_not_string_like(ls):
441+
if len(ls) == 2 and _is_iterable_not_string_like(ls[1]):
442+
# (offset, (on, off, on, off, ...))
443+
offset, onoff = ls
444+
else:
445+
# For backcompat: (on, off, on, off, ...); the offset is implicit.
446+
offset = 0
447+
onoff = ls
448+
449+
if (isinstance(offset, Number)
450+
and len(onoff) % 2 == 0
451+
and all(isinstance(elem, Number) for elem in onoff)):
452+
return (offset, onoff)
453+
488454
raise ValueError(f"linestyle {ls!r} is not a valid on-off ink sequence.")
489455

490456

@@ -927,7 +893,7 @@ def _convert_validator_spec(key, conv):
927893
# text props
928894
"text.color": validate_color,
929895
"text.usetex": validate_bool,
930-
"text.latex.preamble": _validate_tex_preamble,
896+
"text.latex.preamble": validate_string,
931897
"text.hinting": ["default", "no_autohint", "force_autohint",
932898
"no_hinting", "auto", "native", "either", "none"],
933899
"text.hinting_factor": validate_int,
@@ -1187,7 +1153,7 @@ def _convert_validator_spec(key, conv):
11871153

11881154
"pgf.texsystem": ["xelatex", "lualatex", "pdflatex"], # latex variant used
11891155
"pgf.rcfonts": validate_bool, # use mpl's rc settings for font config
1190-
"pgf.preamble": _validate_tex_preamble, # custom LaTeX preamble
1156+
"pgf.preamble": validate_string, # custom LaTeX preamble
11911157

11921158
# write raster image data into the svg file
11931159
"svg.image_inline": validate_bool,

lib/matplotlib/tests/test_rcparams.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ def generate_validator_testcases(valid):
390390
([1, 2, 3], ValueError), # sequence with odd length
391391
(1.23, ValueError), # not a sequence
392392
(("a", [1, 2]), ValueError), # wrong explicit offset
393+
((None, [1, 2]), ValueError), # wrong explicit offset
393394
((1, [1, 2, 3]), ValueError), # odd length sequence
394395
(([1, 2], 1), ValueError), # inverted offset/onoff
395396
)

0 commit comments

Comments
 (0)