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

Skip to content

Commit 9f6f71d

Browse files
committed
Simplify some checks in widgets.
1 parent f71ec63 commit 9f6f71d

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

lib/matplotlib/widgets.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,13 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
311311
super().__init__(ax)
312312

313313
if slidermin is not None and not hasattr(slidermin, 'val'):
314-
raise ValueError("Argument slidermin ({}) has no 'val'"
315-
.format(type(slidermin)))
314+
raise ValueError(
315+
f"Argument slidermin ({type(slidermin)}) has no 'val'")
316316
if slidermax is not None and not hasattr(slidermax, 'val'):
317-
raise ValueError("Argument slidermax ({}) has no 'val'"
318-
.format(type(slidermax)))
319-
if orientation not in ['horizontal', 'vertical']:
320-
raise ValueError("Argument orientation ({}) must be either"
321-
"'horizontal' or 'vertical'".format(orientation))
317+
raise ValueError(
318+
f"Argument slidermax ({type(slidermax)}) has no 'val'")
319+
cbook._check_in_list(['horizontal', 'vertical'],
320+
orientation=orientation)
322321

323322
self.orientation = orientation
324323
self.closedmin = closedmin
@@ -629,8 +628,8 @@ def set_active(self, index):
629628
ValueError
630629
If *index* is invalid.
631630
"""
632-
if not 0 <= index < len(self.labels):
633-
raise ValueError("Invalid CheckButton index: %d" % index)
631+
if index not in range(len(self.labels)):
632+
raise ValueError(f'Invalid CheckButton index: {index}')
634633

635634
l1, l2 = self.lines[index]
636635
l1.set_visible(not l1.get_visible())
@@ -1045,8 +1044,8 @@ def set_active(self, index):
10451044
10461045
Callbacks will be triggered if :attr:`eventson` is True.
10471046
"""
1048-
if 0 > index >= len(self.labels):
1049-
raise ValueError("Invalid RadioButton index: %d" % index)
1047+
if index not in range(len(self.labels)):
1048+
raise ValueError(f'Invalid RadioButton index: {index}')
10501049

10511050
self.value_selected = self.labels[index].get_text()
10521051

0 commit comments

Comments
 (0)