Skip to content

Commit dd3dba5

Browse files
committed
Do not check value of parameters from rcParam (and check rcParam before using them)
1 parent 0b8bd96 commit dd3dba5

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,7 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge",
27572757
if key in kwargs:
27582758
raise ValueError(
27592759
f"Passing {key!r} to bar_label() is not supported.")
2760+
_api.check_in_list(['edge', 'center'], label_type=label_type)
27602761

27612762
a, b = self.yaxis.get_view_interval()
27622763
y_inverted = a > b
@@ -2768,8 +2769,6 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge",
27682769
def sign(x):
27692770
return 1 if x >= 0 else -1
27702771

2771-
_api.check_in_list(['edge', 'center'], label_type=label_type)
2772-
27732772
bars = container.patches
27742773
errorbar = container.errorbar
27752774
datavalues = container.datavalues

lib/matplotlib/font_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ def set_style(self, style):
740740
"""
741741
if style is None:
742742
style = mpl.rcParams['font.style']
743-
_api.check_in_list(['normal', 'italic', 'oblique'], style=style)
743+
else:
744+
_api.check_in_list(['normal', 'italic', 'oblique'], style=style)
744745
self._slant = style
745746

746747
def set_variant(self, variant):
@@ -753,7 +754,8 @@ def set_variant(self, variant):
753754
"""
754755
if variant is None:
755756
variant = mpl.rcParams['font.variant']
756-
_api.check_in_list(['normal', 'small-caps'], variant=variant)
757+
else:
758+
_api.check_in_list(['normal', 'small-caps'], variant=variant)
757759
self._variant = variant
758760

759761
def set_weight(self, weight):

lib/matplotlib/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def __init__(self, ax,
260260
cm.ScalarMappable.__init__(self, norm, cmap)
261261
if origin is None:
262262
origin = mpl.rcParams['image.origin']
263-
_api.check_in_list(["upper", "lower"], origin=origin)
263+
else:
264+
_api.check_in_list(["upper", "lower"], origin=origin)
264265
self.origin = origin
265266
self.set_filternorm(filternorm)
266267
self.set_filterrad(filterrad)
@@ -792,7 +793,8 @@ def set_interpolation_stage(self, s):
792793
"""
793794
if s is None:
794795
s = "data" # placeholder for maybe having rcParam
795-
_api.check_in_list(['data', 'rgba'], s=s)
796+
else:
797+
_api.check_in_list(['data', 'rgba'], s=s)
796798
self._interpolation_stage = s
797799
self.stale = True
798800

lib/matplotlib/lines.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ def __init__(self, xdata, ydata, *,
350350
if solid_joinstyle is None:
351351
solid_joinstyle = mpl.rcParams['lines.solid_joinstyle']
352352

353-
if drawstyle is None:
354-
drawstyle = 'default'
355-
356353
self._dashcapstyle = None
357354
self._dashjoinstyle = None
358355
self._solidjoinstyle = None
@@ -1090,7 +1087,8 @@ def set_drawstyle(self, drawstyle):
10901087
"""
10911088
if drawstyle is None:
10921089
drawstyle = 'default'
1093-
_api.check_in_list(self.drawStyles, drawstyle=drawstyle)
1090+
else:
1091+
_api.check_in_list(self.drawStyles, drawstyle=drawstyle)
10941092
if self._drawstyle != drawstyle:
10951093
self.stale = True
10961094
# invalidate to trigger a recache of the path

lib/matplotlib/markers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ def _set_fillstyle(self, fillstyle):
291291
"""
292292
if fillstyle is None:
293293
fillstyle = mpl.rcParams['markers.fillstyle']
294-
_api.check_in_list(self.fillstyles, fillstyle=fillstyle)
294+
else:
295+
_api.check_in_list(self.fillstyles, fillstyle=fillstyle)
295296
self._fillstyle = fillstyle
296297
self._recache()
297298

lib/matplotlib/mlab.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
244244

245245
if mode is None or mode == 'default':
246246
mode = 'psd'
247-
_api.check_in_list(
248-
['default', 'psd', 'complex', 'magnitude', 'angle', 'phase'],
249-
mode=mode)
247+
else:
248+
_api.check_in_list(
249+
['default', 'psd', 'complex', 'magnitude', 'angle', 'phase'],
250+
mode=mode)
250251

251252
if not same_data and mode != 'psd':
252253
raise ValueError("x and y must be equal if mode is not 'psd'")
@@ -262,7 +263,8 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
262263
sides = 'twosided'
263264
else:
264265
sides = 'onesided'
265-
_api.check_in_list(['default', 'onesided', 'twosided'], sides=sides)
266+
else:
267+
_api.check_in_list(['default', 'onesided', 'twosided'], sides=sides)
266268

267269
# zero pad x and y up to NFFT if they are shorter than NFFT
268270
if len(x) < NFFT:

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,8 @@ def _convert_validator_spec(key, conv):
930930

931931
## font props
932932
"font.family": validate_stringlist, # used by text object
933-
"font.style": validate_string,
934-
"font.variant": validate_string,
933+
"font.style": ['normal', 'italic', 'oblique'],
934+
"font.variant": ['normal', 'small-caps'],
935935
"font.stretch": validate_fontstretch,
936936
"font.weight": validate_fontweight,
937937
"font.size": validate_float, # Base font size in points

0 commit comments

Comments
 (0)