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

Skip to content

Commit 6a6527c

Browse files
authored
Merge pull request #14280 from anntzer/validate_markevery
Simplify validate_markevery logic.
2 parents 0b8544b + b6b5acc commit 6a6527c

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

lib/matplotlib/rcsetup.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -580,37 +580,26 @@ def validate_markevery(s):
580580
length-2 tuple of floats, list of ints
581581
582582
"""
583-
# Validate s against type slice
584-
if isinstance(s, slice):
583+
# Validate s against type slice float int and None
584+
if isinstance(s, (slice, float, int, type(None))):
585585
return s
586586
# Validate s against type tuple
587587
if isinstance(s, tuple):
588-
tupMaxLength = 2
589-
tupType = type(s[0])
590-
if len(s) != tupMaxLength:
591-
raise TypeError("'markevery' tuple must have a length of "
592-
"%d" % (tupMaxLength))
593-
if tupType is int and not all(isinstance(e, int) for e in s):
594-
raise TypeError("'markevery' tuple with first element of "
595-
"type int must have all elements of type "
596-
"int")
597-
if tupType is float and not all(isinstance(e, float) for e in s):
598-
raise TypeError("'markevery' tuple with first element of "
599-
"type float must have all elements of type "
600-
"float")
601-
if tupType is not float and tupType is not int:
602-
raise TypeError("'markevery' tuple contains an invalid type")
588+
if (len(s) == 2
589+
and (all(isinstance(e, int) for e in s)
590+
or all(isinstance(e, float) for e in s))):
591+
return s
592+
else:
593+
raise TypeError(
594+
"'markevery' tuple must be pair of ints or of floats")
603595
# Validate s against type list
604-
elif isinstance(s, list):
605-
if not all(isinstance(e, int) for e in s):
606-
raise TypeError("'markevery' list must have all elements of "
607-
"type int")
608-
# Validate s against type float int and None
609-
elif not isinstance(s, (float, int)):
610-
if s is not None:
611-
raise TypeError("'markevery' is of an invalid type")
612-
613-
return s
596+
if isinstance(s, list):
597+
if all(isinstance(e, int) for e in s):
598+
return s
599+
else:
600+
raise TypeError(
601+
"'markevery' list must have all elements of type int")
602+
raise TypeError("'markevery' is of an invalid type")
614603

615604

616605
validate_markeverylist = _listify_validator(validate_markevery)

0 commit comments

Comments
 (0)